第几天?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 72342 Accepted Submission(s): 27369
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20 2006/3/12
Sample Output
20 71
#include<stdio.h>
int main()
{
int a,b,c,d;
while(scanf("%d/%d/%d",&a,&b,&c)!=EOF)
{
if((((a%4)==0)&&(a%100)!=0)||(a%400==0))
switch(b)
{
case 1: d=c; break;
case 2: d=31+c; break;
case 3: d=60+c; break;
case 4: d=91+c; break;
case 5: d=121+c; break;
case 6: d=152+c; break;
case 7: d=182+c; break;
case 8: d=213+c; break;
case 9: d=244+c; break;
case 10:d=274+c; break;
case 11:d=305+c; break;
case 12:d=335+c; break;
}
else
switch(b)
{
case 1: d=c; break;
case 2: d=31+c; break;
case 3: d=59+c; break;
case 4: d=90+c; break;
case 5: d=120+c; break;
case 6: d=151+c; break;
case 7: d=181+c; break;
case 8: d=212+c; break;
case 9: d=243+c; break;
case 10:d=273+c; break;
case 11:d=304+c; break;
case 12:d=334+c; break;
}
printf("%d\n",d);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n,a,b,c;
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cin>>n;
while(n--)
{
int num=0;
cin>>a>>b>>c;
for(int i=0;i<b-1;i++)
num+=m[i];
if((((a%4==0)&&(a%100!=0))||(a%400==0)) && (b>2))
num++;
cout<<num+c<<endl;
}
}