Friday the Thirteenth-section1.1
来源:互联网 发布:网络直播间策划方案 编辑:程序博客网 时间:2024/06/01 08:05
题目大意
计算每个月的十三号落在周一到周日的次数,1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400. 并规定: 1900年1月1日是星期一. 4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天. 年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).
输入格式
line 1:N
输出格式
一行七个整数,并用空格分开,分别表示13号落在周六,周日,周一,...,周五的次数
样例输入
20
样例输出
36 33 34 33 35 35 34
题解
从1900年1月1日开始,记算到每年每月第13天的间隔天数,并模七;结合1900年1月1日是周一的条件,计算出13号是周几,并记录下来。
代码
#include<stdio.h>int ifleapyear(int year){if(year%4==0&&year%100!=0) return 1;if(year%400==0) return 1;return 0;}int main(){ unsigned int day=0;int week[8]={0},year=1900,N,month,i,num=6,flag;int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};scanf("%d",&N);for(i=0;i<N;i++,year++){ monthday[2]=28; flag=ifleapyear(year); if(flag) {monthday[2]=29;} for(month=1;month<=12;month++) { day=day+13; num=day%7; num=num+1-1; num=num%7; week[num]++; day=day-13; day=day+monthday[month]; }}printf("%d",week[6]);printf(" %d",week[0]);for(i=1;i<6;i++) printf(" %d",week[i]);printf("\n");return 0;}
阅读全文
0 0
- Friday the Thirteenth-section1.1
- 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
- USCAO-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.3 Friday the Thirteenth
- [USACO1.1]Friday the Thirteenth
- usaco 1-1-3 Friday the Thirteenth
- USACO-cha1-sec1.1 Friday the Thirteenth
- USACO1.1 Friday the Thirteenth 比较分析
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- Friday the Thirteenth
- jquery 判断input框中不能输入特殊字符(#¥%……&*@)
- spring注解大全
- 对consumer instance(消费者实例)的思考
- ZooKeeper 基础知识、部署和应用程序
- 对于java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误解决
- Friday the Thirteenth-section1.1
- 《Oracle Database 11gR2性能调整与优化》第一节
- C++中的虚函数的理解和使用
- MQ学习(一)--- JMS了解
- node.js 使用域账号登陆电脑 同一域 可以访问调试项目
- query.list()和query.iterate()区别
- AndroidManifest.xml点点滴滴
- 从输入网址到网页完整展现到底发生了什么?
- iOS跳转系统设置方法支持iOS7~iOS10+