https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d?tpId=40&tqId=21350&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking&tab=answerKey
用1月1 累加到目标天数
#include<cstdio>
#include<iostream>
using namespace std;
int m[13]={
0,31,28,31,30,31,30,31,31,30,31,30,31};
bool judge(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return true;
return false;
}
int main(void)
{
int year,month,day;
while(cin>>year>>month>>day)
{
if(judge(year))
{
m[2]=29;
}
int a=1;//月
int b=1;//天
int sum=1;
while(a!=month||b!=day)
{
sum++;
b++;
if(b>m[a])
{
a++;
b=1;
}
}
m[2]=28;
cout<<sum<<endl;
}
return 0;
}
#include<cstdio>
#include<iostream>
using namespace std;
int m[13]={
0,31,28,31,30,31,30,31,31,30,31,30,31};
bool judge(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return true;
return false;
}
int main(void)
{
int year,month,day;
while(cin>>year>>month>>day)
{
int sum=0;
if(judge(year))
{
m[2]=29;
}
for(int i=1;i<=month-1;i++)
{
sum+=m[i];
}
m[2]=28;
cout<<sum+day<<endl;
}
return 0;
}