Friday the Thirteenth-section1.1
2017-05-26 17:15
183 查看
题目大意
计算每个月的十三号落在周一到周日的次数,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; }
相关文章推荐
- uscao Section 1.1 Friday the Thirteenth
- USACO section 1.1 Friday the Thirteenth
- Section 1.1 PROB Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth
- Section 1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth [日期]
- USCAO-Section1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth[日期]
- USACO:Section 1.1 Friday the Thirteenth
- USACO Section 1.1 Friday the Thirteenth
- USACO Section 1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth【泰勒公式】
- USACO Section 1.1-3 Friday the Thirteenth
- USACO - Chapter1 Section 1.1 - Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth
- uscao Section 1.1 Friday the Thirteenth
- USACO-Section1.2 Friday the Thirteenth (简单日期处理)
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth