2017年12月16日 星期六

[ITSA Exam.60] Problem 1. 平、閏年判定(C++)

Problem 1. 平、閏年判定

                     (Time Limit: 1 second)

問題描述 :

試撰寫一個程式,可由鍵盤讀入一個 4 位數的整數,代表西洋的年份,然後判別這個年份是否為閏年每四年一閏,每百年不閏,每四百年一閏,例如西1900 雖為 4 的倍數,但可被 100 整除,所以不是閏年,同理, 2000 年是
閏年,因可被 400 整數,而 2004 當然也是閏年,因可以被 4 整除

輸入說明:

第一行輸入一正整數 N(1≤N≤10),表示共有 N 筆測資,每筆測資輸入一 4 位數的整數,表示西元年份。

輸出說明:

輸出閏年(Bissextile Year)或平年(Common Year)

範例:


Sample Input:
Sample Output:
2
2000
2003
Bissextile Year Common Year


  1. #include <iostream>  
  2. using namespace std;  
  3.    
  4. int main() {  
  5.     // Problem 1. 平、閏年判定  
  6.     int n;  
  7.     cin >> n;  
  8.     for(int i = 0;i<n;i++)  
  9.     {  
  10.         int years;  
  11.         cin >> years;  
  12.         if(years %400==0)  
  13.         {  
  14.             cout << "Bissextile Year" << endl;  
  15.         }  
  16.         else if(years%4==0 && years%100!=0)  
  17.         {  
  18.             cout << "Bissextile Year" << endl;  
  19.         }  
  20.         else  
  21.         {  
  22.             cout << "Common Year" << endl;  
  23.         }  
  24.     }  
  25.     return 0;  
  26. }  

沒有留言:

張貼留言