Friday the Thirteenth(USACO)
来源:互联网 发布:php static 编辑:程序博客网 时间:2024/06/12 00:57
http://train.usaco.org/usacoprob2?a=yDGYEVaITpf&S=friday
题意:问你从1900年1月1日到1900 + n - 1年12月31日每个月的13日出现在星期几,然后把出现频率依次打印出来,打印顺序依次为星期六,星期日,星期一,星期二,星期三,星期四,星期五。
思考:本身是一道很水的题,不过一定要看输出格式,输出是要从星期六开始输出,因为这个问题调了很长时间。
源码忘存了,所以下面的代码是官网上的代码。
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>intisleap(int y){ return y%4==0 && (y%100 != 0 || y%400 == 0);}int mtab[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };/* return length of month m in year y */intmlen(int y, int m){ if(m == 1) /* february */ return mtab[m]+isleap(y); else return mtab[m];}voidmain(void){ FILE *fin, *fout; int i, m, dow, n, y; int ndow[7]; fin = fopen("friday.in", "r"); fout = fopen("friday.out", "w"); assert(fin != NULL && fout != NULL); fscanf(fin, "%d", &n); for(i=0; i<7; i++) ndow[i] = 0; dow = 0; /* day of week: January 13, 1900 was a Saturday = 0 */ for(y=1900; y<1900+n; y++) { for(m=0; m<12; m++) { ndow[dow]++; dow = (dow+mlen(y, m)) % 7; } } for(i=0; i<7; i++) { if(i) fprintf(fout, " "); fprintf(fout, "%d", ndow[i]); } fprintf(fout, "\n"); exit(0);}
0 0
- Friday the Thirteenth(USACO)
- Friday the Thirteenth(USACO)
- usaco--Friday the Thirteenth
- [USACO] Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO:Friday the Thirteenth
- USACO -Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO--Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- (usaco) Friday the Thirteenth 黑色星期五
- usaco Friday the Thirteenth (数星期)
- USACO 1.1-Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- Android(JAVA)线程池ThreadPoolExecutor
- 实时显示
- 迭代器和解析
- 数据库学习计划
- 面试题1
- Friday the Thirteenth(USACO)
- 数组合并
- 建议109:谨慎使用嵌套类
- 我的第一篇博客
- 带缓存功能的图片查看器
- js追加元素的几种方法(append()、prepend()、after()、before()、insertAfter()、insertBefore())
- 动态规划-菲波那切数列--DP_2
- nodejs学习(一)
- C# 线程池ThreadPool的用法简析