题解 | #今年的第几天?#
今年的第几天?
http://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d
#include<bits/stdc++.h>
using namespace std;
int Isleapyear(int y) //判断是否为闰年
{
return ((y%100!=0&&y%4==0)||(y%400==0));
}
int daytab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; //预处理
int main()
{
int year,month,day;
while(scanf("%d %d %d",&year,&month,&day)!=EOF)
{
int k=0;
int row=Isleapyear(year); //判断用daytab中的哪一行
for(int j=0;j<month;j++)
{
k=k+daytab[row][j];
}
k=k+day;
printf("%d\n",k);
}
return 0;
}
using namespace std;
int Isleapyear(int y) //判断是否为闰年
{
return ((y%100!=0&&y%4==0)||(y%400==0));
}
int daytab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; //预处理
int main()
{
int year,month,day;
while(scanf("%d %d %d",&year,&month,&day)!=EOF)
{
int k=0;
int row=Isleapyear(year); //判断用daytab中的哪一行
for(int j=0;j<month;j++)
{
k=k+daytab[row][j];
}
k=k+day;
printf("%d\n",k);
}
return 0;
}