日期计算
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
1
-
描述
- 如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
-
输入
- 第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。 输出
- 每组输入数据的输出占一行,输出判断出的天数n 样例输入
-
3 2000 4 5 2001 5 4 2010 10 24
样例输出
-
96 124
-
297
-
代码如下:
-
#include<iostream> #include<cstdio> using namespace std; int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //a数组代表1~12月的天数 int main() { int n,year,month,day,s=0,i; cin>>n; while(n--) { s=0; cin>>year>>month>>day; for(i=0;i<month-1;i++) //求月的天数 s+=a[i]; s+=day; //加上天数得总天数 if((year%400==0 || (year%100!=0 && year%4==0)) && month>2)//是闰年并且比2月大s加1,注意如果month<2天数是不用加1的 s++; cout<<s<<endl; } return 0; }