題目連結 http://zerojudge.tw/ShowProblem?problemid=a004,根據題目給的提示:西元年被4整除且不被100整除,或被400整除者即為閏年。即可完成此題了。
程式碼如下:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
short y; | |
while(cin >> y){ | |
y = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0); | |
cout << (y == 1?"閏年":"平年") << endl; | |
} | |
return 0; | |
} |
沒有留言:
張貼留言