USACO-Section1.1 Friday the Thirteenth
来源:互联网 发布:c语言a两个中括号 编辑:程序博客网 时间:2024/06/13 02:22
2017-5-24
题目描述
输入N表示年数,算出从1900年1月1日到1900+N-1年12月31日每个月13号为星期几,输出周6,7,1,2,3,4,5的天数
解答
我是求出每个月距离1900年1月1日的天数然后对7求余即可,注意处理平年和闰年
代码
/*ID: 18795871PROG: fridayLANG: C++*/#include<iostream>#include<fstream>#include<cstring>using namespace std;ifstream fin("friday.in");ofstream fout("friday.out");int day[2][13] = {31,31,28,31,30,31,30,31,31,30,31,30,0,31,31,29,31,30,31,30,31,31,30,31,30,0};int r[8];int res(int n){ if (n%4==0 && n%100!=0 || n%400==0) return 1; return 0;}int main(){ int i,n; fin>>n; memset(r,0,sizeof(r)); r[6]=1; int sum = 12,year = 1900,p; for (i=1 ;i<=12*n-1 ;i++){ p = res(year); sum += day[p][i%12]; r[sum%7+1] += 1; if (i%12 == 0) year += 1; } fout<<r[6]<<" "<<r[7]<<" "; for (i=1; i<=4; i++) fout<<r[i]<<" "; fout<<r[5]<<endl; return 0;}
阅读全文
1 0
- 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-Section1.1 Friday the Thirteenth【泰勒公式】
- USACO之Section1.1.3 Friday the Thirteenth
- Friday the Thirteenth-section1.1
- USCAO-Section1.1 Friday the Thirteenth
- 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
- Linux下调用系统终端命令popen()
- postfix + mariadb
- 相机模型与多视几何
- 图解归并排序算法(java版)
- 挂载磁盘 以及 磁盘扩容
- USACO-Section1.1 Friday the Thirteenth
- Apache+Tomcat实现负载均衡及集群(session同步)--三、动静分离(2)使用mod_proxy
- jdbc-批操作和元数据
- Apache+Tomcat实现负载均衡及集群(session同步)--四、负载均衡(1)使用mod_jk
- 2017东北四省赛G题
- iOS10 相机相册等权限的使用
- 汉诺塔问题
- 基于NIOS-II的示波器:PART4 系统调试&测试
- Kotlin语法(一)