usaco 1-1-3 Friday the Thirteenth
来源:互联网 发布:windows ntp服务器配置 编辑:程序博客网 时间:2024/06/05 07:06
usaco持续更新中。
nocow友情翻译
描述
13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.
注意,开始今年是一千九百年,不是1990
这里有一些你要知道的:
1、1900年1月1日是星期一.
2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.
3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).
4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.
请不要调用现成的函数
请不要预先算好数据(就是叫不准打表)!
[编辑]格式
PROGRAM NAME: friday
INPUT FORMAT:
(friday.in)
一个正整数n.
OUTPUT FORMAT:
(friday.out)
七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一...星期五的次数..
[编辑]SAMPLE INPUT
20
[编辑]SAMPLE OUTPUT
36 33 34 33 35 35 34
分析:也就是说,求1900年开始到1900+n-1年,星期1,2,3,4,5,6,7各有多少天。
上代码!
/*ID:jwb11931LANG:CTASK:friday*/#include<stdio.h>int n,w,i,j,years,w1,b[8];int main(){int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};freopen("friday.in","r",stdin);freopen("friday.out","w",stdout);scanf("%d",&n);w=1;for(i=1;i<=n;i++){a[2]=28;years=1900+i-1;if(years%4==0&&years%100!=0||years%400==0)a[2]=29;//判闰年for(j=1;j<=12;j++){//w表示上月的星期if(years==1900&&j==1){//对1900年1月单独算w=6;b[6]++;}else if(j==1){//1月单独算,因为要弄到去年w1=(a[12]+1)%7+w-1;w=w1%7;b[w]++;}if(j!=1){w1=(a[j-1]+1)%7+w-1;w=w1%7;b[w]++;}}}printf("%d %d %d %d %d %d %d\n",b[6],b[0],b[1],b[2],b[3],b[4],b[5]);//注意,从星期天开始。return 0;}
1 0
- usaco 1-1-3 Friday the Thirteenth
- USACO-cha1-sec1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth[日期]
- USACO Section1.1 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth (friday)
- 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
- Log4j使用总结
- linux面试之你认识的fork、vfork、clone
- 管道createnamepipe
- PCB布线及相关规则设置
- 认识Unix时间戳
- usaco 1-1-3 Friday the Thirteenth
- LeetCode Power of Two
- implements 和extend
- 启动Activity的两种方式startActivity和startActivityForResult(二)
- swift资料收集
- 给磁盘文件排序
- 好客户端是怎样炼成的
- easyui使用Ajax提交表单,返回Json数据
- html5 学习笔记--jikexueyuan的视频看完后的碎碎念(与HTML4相比的改变)