题目来源:http://116.56.140.75:8000/JudgeOnline/problem.php?id=1713
1713: 二月份有多少天?
时间限制: 1 Sec 内存限制: 64 MB题目描述
根据现行公历历法,二月份的天数一般是28天,但是如果是闰年的二月份就是29天。给定某个年份,你是否能确定二月份到底有多少天吗?
输入
第一行包含一个整数n(1≤n≤100),表示测试用例的个数。其后的n行,每行有一个非负整数。
输出
每个测试用例输出一行。输出该年的2月份的天数。
样例输入
4
1900
2000
2004
2009
样例输出
28
29
29
28
解析:主要在于闰年,平年的判断
代码:
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
int y;
cin >> y;
if (y % 100 == 0)
{
if (y % 400 == 0)
cout << "29" << endl;
else
cout << "28" << endl;
}
else
{
if (y % 4 == 0)
cout << "29" << endl;
else
cout << "28" << endl;
}
}
}
/**************************************************************
Problem: 1713
User: 201730685257
Language: C++
Result: 正确
Time:0 ms
Memory:1484 kb
****************************************************************/