USACO 1.1.3 Friday the Thirteenth
2012-02-20 19:17
375 查看
比较简单,直接模拟,需要注意闰年的判断和对不同月份日期的处理。
代码如下:
代码如下:
/* ID: michael139 LANG: C PROG: friday */ #include<stdio.h> #include<string.h> int is_leapYear(int y); int main () { FILE *fin = fopen ("friday.in", "r"); FILE *fout = fopen ("friday.out", "w"); int n,i,j,cur,count[7]; while (fscanf(fin,"%d",&n) != EOF) { memset(count,0,sizeof(count)); cur = 2;//Monday for (i=1900;i<=1900+n-1;i++) { for (j=1;j<=12;j++) { cur += 12; count[cur%7] ++ ; if (j==1 || j==3 || j==5 || j==7 || j==8 || j==10 || j==12) { cur += 19; } else if (j==4 || j==6 || j==9 || j==11) { cur += 18; } else { if (is_leapYear(i)) cur += 17; else cur += 16; } } } for (i=0;i<7;i++) { fprintf(fout,"%d",count[i]); if (i!=6) fprintf(fout," "); } fprintf(fout,"\n"); } return 0; } int is_leapYear(int y) { return (y%4==0) && (y%100!=0 || y%400==0); }
相关文章推荐
- USACO 1.1.3 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth (friday)
- Usaco 1.1.3 黑色星期五(Friday the Thirteenth)
- USACO1.1.3 Friday the Thirteenth (friday)
- USACO 1.1.3 Friday the Thirteenth (friday)
- USACO 1.1.3 Friday the Thirteenth
- USACO1.1.3[Friday The Thirteenth]
- USACO1.1.3 - Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- usaco1.1.3 Friday the Thirteenth黑色星期五
- 【USACO题库】1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3--Friday the Thirteenth
- [USACO 1.1.3] Friday the Thirteenth
- USACO 1.1.3 - Friday the Thirteenth(模拟)
- USACO之Section1.1.3 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth 13日星期五