南阳219----An problem about date
1 /* 2 1600年一月一日为星期6,所以算出ymd与1600-1-1差多少天对7取余即可 3 */ 4 #include<stdio.h> 5 int a[10000]={0}; 6 int main() 7 { 8 int i,y,m,d,t = 0,ans; 9 for(i=1600; i<9601; i+=4) 10 { 11 if(i%100 != 0 || i%400==0) 12 ++t; 13 a[i-1599] = a[i-1598] = a[i-1597] = a[i-1596] = t; 14 } 15 while(~scanf("%d%d%d",&y,&m,&d)) 16 { 17 ans = 5 + (y-1600)*365 + a[y-1600]; 18 switch(m) 19 { 20 case 2:d+=31;break; 21 case 3:d+=59;break; 22 case 4:d+=90;break; 23 case 5:d+=120;break; 24 case 6:d+=151;break; 25 case 7:d+=181;break; 26 case 8:d+=212;break; 27 case 9:d+=243;break; 28 case 10:d+=273;break; 29 case 11:d+=304;break; 30 case 12:d+=334;break; 31 } 32 if( (m>2 && y%4==0 && y%100!=0) || y%400==0 && m>2) 33 d++; 34 ans += d; 35 printf("%d\n",ans%7); 36 } 37 return 0; 38 }
1 //最优解 2 #include<cstdio> 3 int main() 4 { 5 int y,m,d; 6 while(~scanf("%d%d%d",&y,&m,&d)) 7 { 8 if(m<3) m+=12,--y; 9 printf("%d\n",(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7); //蔡勒公式的变种 10 } 11 }