【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
来源:互联网 发布:cad标注尺寸数据不对 编辑:程序博客网 时间:2024/05/29 16:59
题目描述
13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.
这里有一些你要知道的:
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年是闰年.
请不要调用现成的函数
请不要预先算好数据(就是叫不准打表)!
输入输出格式
输入格式:
一个正整数n.
输出格式:
输入输出样例
输入样例#1:
20
输出样例#1:
36 33 34 33 35 35 34
说明
题目翻译来自NOCOW。
USACO Training Section 1.1
代码
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int ans[8];void read(int &x){ x=0; char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); }}int main(){ int n,pos=1; read(n); for(int i=1900;i<=1900+n-1;++i) { for(int j=1;j<=12;++j) { int k; if((i%4==0&&i%100!=0)||(i%400==0&&i%100==0)) { if(j==4||j==6||j==9||j==11)k=30; else if(j==2)k=29; else k=31; for(int t=1;t<=k;++t) { pos++; if(pos==8)pos=1; if(t==13)ans[pos]++; } } else { if(j==4||j==6||j==9||j==11)k=30; else if(j==2)k=28; else k=31; for(int t=1;t<=k;++t) { pos++; if(pos==8)pos=1; if(t==13)ans[pos]++; } } } } printf("%d %d %d %d %d %d %d",ans[7],ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]); return 0;}
0 0
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- 【USACO1.1_3】★Friday the Thirteenth 黑色星期五
- usaco1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3 Friday the Thirteenth(黑色星期五)
- [USACO1.1]Friday the Thirteenth
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth 黑色星期五
- USACO1.1 Friday the Thirteenth 比较分析
- Friday the Thirteenth(黑色星期五) USACO
- USACO1.1.3[Friday The Thirteenth]
- USACO1.1.3 Friday the Thirteenth
- USACO1.1.3 - Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- 蓝桥杯 算法训练 寻找数组中最大值 JAVA
- jmeter参数化随机取值实现
- centos 7配置静态IP,并配置DNS
- Windows的使用技巧(一)
- 教你如何使用php session
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- Python的一些实用技巧(1)
- 指针+二维数组
- python高手的自修课
- 设计模式之Future模式例子
- 20170506@泛型
- 可变参数列表剖析
- web后端php学习路线
- python数据分析与挖掘实战—聚类算法对比