2369 - 打印某年某月有多少天
打印某年某月有多少天。
(提示:A、闰年的计算方法:年数能被4整除,并且不能被100整除;或者能被400整除的整数年份。)
Input
输入只有一行,包括2个整数,中间用空格空开。
Output
输出只有一行,包括一个整数。
Examples
Input
2004 2
Output
29
Hint
(提示:A、闰年的计算方法:年数能被4整除,并且不能被100整除;或者能被400整除的整数年份。)
Solution C++
#include<iostream> using namespace std; int main() { int year,month; cin>>year>>month; switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12:cout<<31<<endl;break; case 4: case 6: case 9: case 11:cout<<30<<endl;break; case 2: if((year%4==0 && year%100!=0) || year%400==0) { cout<<29<<endl;break; } else { cout<<28<<endl;break; } } return 0; }
Hint
(提示:A、闰年的计算方法:年数能被4整除,并且不能被100整除;或者能被400整除的整数年份。)