计蒜客 练习题 日期计算 date calculation
Last year, Zhao Yuehan and Lu Ran are in love. One time, Lu Ran was teaching C language for Zhao Yuehan. But, Zhao Yuehan suddenly asked Lu Ran a question:’How long have we been in love?’ Surely, Lu Ran didn’t answer the question correctly, so Zhao Yuehan got angry.
To prevent the same thing from happening again, Lu Ran hope you can help him write a program to calculate the date.(We assume that 2017.8.17 is one day the whole)
Input:
The first line contains an integer tt which shows the number of test case.(1\le t \le 10)(1≤t≤10)
Each case contain three integers Y, M and D where Y is the year, M is the month and D is the day.(We promise that all the dates are reasonable and are later than 2017.8.17, Y\le 20992017.8.17,Y≤2099)
Output:
For each test case, output a line containing the answer.
样例输入
2 2017 8 17 2018 3 31
样例输出
1 227
#include<stdio.h>
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int flag1(int a)
{
if(a%4==0) return 1;//是闰年
else return 0;
}
int solve(int a,int b,int c)
{
int ans=0;
for(int i=1;i<b;i++)
ans+=m[i];
ans+=c;
if(flag1(a)&&a>2) ans++;
while(a>2017){
ans+=365;
if(flag1(a)) ans++;
a--;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int ans=solve(a,b,c);
printf("%d\n",ans-228);
}
return 0;
}