题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include <iostream>
using namespace std;
int main()
{
int year,mon,day;
while(cin>>year>>mon>>day)
{
int sum=0;
if(mon==1)
{
cout<<day<<endl;
}
else
{
sum=(mon-1)*30;
if(mon==2)
cout<<sum+1+day<<endl;
if(mon==3)
{
if(year%4==0)
cout<<sum-1+day<<endl;
else
cout<<sum-1+day<<endl;
}
if(mon==4||mon==5)
{
if(year%4==0)
cout<<sum+1+day<<endl;
else
cout<<sum+day<<endl;
}
if(mon==6||mon==7)
{
if(year%4==0)
cout<<sum+2+day<<endl;
else
cout<<sum+1+day<<endl;
}
if(mon==8)
{
if(year%4==0)
cout<<sum+3+day<<endl;
else
cout<<sum+2+day<<endl;
}
if(mon==9||mon==10)
{
if(year%4==0)
cout<<sum+4+day<<endl;
else
cout<<sum+3+day<<endl;
}
if(mon==11||mon==12)
{
if(year%4==0)
cout<<sum+5+day<<endl;
else
cout<<sum+4+day<<endl;
}
}
}
return 0;
}
查看25道真题和解析
阿里云工作强度 647人发布