日历结算只能找规律,不能模拟(超时)!!!
#include<stdio.h>
#include<math.h>
#include<string.h>
double firstday,firstmonth,firstyear;
double lastday,lastmonth,lastyear;
double sumdays;
double oneyear[15];
void init()
{
sumdays=0;
for(int i=1;i<=12;i++)
{
int t=0;
for(int j=1;j<=i;j++)
{
t+=j*j*j;
}
oneyear[i]=t;
sumdays+=t;
// printf("%d:%d/n",i,total);
}
}
double sumday(int year,int month,int day)
{
double total=0.0;
int cnt=(year)/12;
total+=sumdays*cnt;
int temp=(cnt*12)/11;
total+=temp;
for(int i=temp*11;i<(12*cnt);i++) if(i%11==0) total+=1;
for(int i=12*cnt;i<year;i++)
{
if(i%11==0)
total+=oneyear[i%12+1]+1;
else
total+=oneyear[i%12+1];
}
if(month==1)
{
return total+day;
}
else
{
if(year%11==0)
total+=2;
else
total+=1;
for(int i=2;i<month;i++)
total+=i*i*i;
return total+day;
}
}
int main()
{
init();
char ch1,ch2;
while(scanf("%lf%c%lf%c%lf",&firstmonth,&ch1,&firstday,&ch2,&firstyear)==5)
{
//getchar();
scanf("%lf%c%lf%c%lf",&lastmonth,&ch1,&lastday,&ch2,&lastyear);
// getchar();
double tot1=sumday(firstyear,firstmonth,firstday);
double tot2=sumday(lastyear,lastmonth,lastday);
double tot=fabs(tot1-tot2);
printf("%.0lf/n",tot+1.0);
}
return 0;
}