Problem Description
Fuzhou University is the national 211 Project focused on building
universities, founded in 1958, has become one one of the Fujian
Provincial key university which is mainly Polytechnic combination of
science, engineering, economic and management, literature, law, arts
and other multidisciplinary coordinated development. This year’s
October 25 is the 50th anniversary celebration of the school. Now,
your task is to help the group of teachers who are busy preparing for
the celebration calculate the left time to the nearest celebration.
Input
The first line is a positive number N (N <= 2000), N indicates the
number of test data. The following N lines, each line has three
positive integer, Y, M, D that were year, month, day time
respectively, the three integers are separated by a space, we
guarantee the date is legitimate(1958<= Y <= 3000).
Output
According to input data, you must calculate the left time to the nearest celebration. If the most recent session celebration is N, the left time to the nearest celebration is M, so we must output: “M days left for celebrating the Nth anniversary of the founding of Fuzhou University!” (quotes for clarity only).
Sample Input
3
2008 10 24
2008 10 26
2008 10 25
Sample Output
1 days left for celebrating the 50th anniversary of the founding of Fuzhou University!
0 days left for celebrating the 50th anniversary of the founding of Fuzhou University!
364 days left for celebrating the 51th anniversary of the founding of Fuzhou University!
代码:
#include<stdio.h>
int leap(int x)
{
if((x%4==0&&x%100!=0)||x%400==0)
return 1;
else
return 0;
}
int main()
{
int n,year,day,mon,d,i;
int month[13]={0,31,28,31,30,31,30,31,31,30,25,30,31};//10月特殊处理
scanf("%d",&n);
while(n--)
{d=0;month[2]=28;//对2月初始化
scanf("%d%d%d",&year,&mon,&day);
if((mon==10&&day<=25)||mon<10)//计算在校庆前到校庆的天数
{
if(mon<3&&leap(year))
month[2]=29;//闰年2月为29天
for(i=mon;i<=10;i++)
{d+=(month[i]-day);//printf("1\n");
day=0;
}
}
//计算校庆后到校庆的天数d,并用校庆到第二年校庆的天数减去d得到结果
else if(mon==10)
{
d+=day-month[10];
year++;
if(leap(year)) d=366-d;
else d=365-d;
}
else if(mon==11)
{
d+=6+day;
year++;
if(leap(year)) d=366-d;
else d=365-d;
}
else if(mon==12)
{
d+=36+day;year++;
if(leap(year)) d=366-d;
else d=365-d;
}
printf("%d days left for celebrating the %dth anniversary of the founding of Fuzhou University!\n",
d,year-1958);
}
return 0;
}