水题一道,注意闰年和平年的判断。

hdu2005_HDUhdu2005_HDU_02View Code
#include"iostream"
using namespace std;
int main()
{
int y,m,d;
while(scanf("%d/%d/%d",&y,&m,&d)!=EOF)
{
int sum=0,i;
for(i=1;i<m;i++)
{
switch(i)
{
case 1: sum+=31; break;
case 2:
{
if(y%4==0&&y%100||y%400==0)
{
sum+=29;
}
else sum+=28;
}
break;
case 3: sum+=31; break;
case 4: sum+=30; break;
case 5: sum+=31; break;
case 6: sum+=30; break;
case 7: sum+=31; break;
case 8: sum+=30; break;
case 9: sum+=31; break;
case 10: sum+=30; break;
case 11: sum+=31; break;
}
}
sum+=d;
cout<<sum<<endl;
}
return 0;
}