USACO之Section1.1.3 Friday the Thirteenth
来源:互联网 发布:端口镜像是做什么用的 编辑:程序博客网 时间:2024/06/16 02:04
这道题意为:输入一个N,求从1900年1月1日到1900+n-1年12月31日
其间每个月的第13天是星期几?
输出:从星期6到5的各自的个数。
关键为:求出到1900年1月1日的天数。判断闰年。
先列出一般思路,就是先要判断年份是否为闰年,在用数组去取,每月的天数,最后取余7,得到星期。
这里不再叙述,我将采取基姆拉尔森计算公式的方法去得出星期。
基姆拉尔森计算公式:请自己百度。
关键为:遇到1,2月时将其转为13,14月,同时年份减一。
代码如下:
/*ID: m1519591PROG: fridayLANG: C++ */#include <iostream>#include <fstream>using namespace std;int main() { ofstream fout ("friday.out"); ifstream fin ("friday.in"); int n; int year,month,data=13,week,ans[7]={0}; fin>>n; for(int i=1900;i<=1900+n-1;i++) { year=i; for(int j=1;j<=12;j++) { month=j; if(j==1||j==2) { month+=12; year--; } week=(data+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7; ans[week]++; if(month>12) year++; } } fout<<ans[5]<<" "<<ans[6]<<" "; for(int i=0;i<=3;i++) fout<<ans[i]<<" "; fout<<ans[4]<<endl; return 0;}
阅读全文
0 0
- USACO之Section1.1.3 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之Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth【泰勒公式】
- Friday the Thirteenth-section1.1
- 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
- hdoj1034 Candy Sharing Game(简单题)
- TCP/UDP/HTTP
- struts零散知识累积(一)
- Magento 2中文文档教程
- C#方法重载(overload)、重写(覆盖)(override)、隐藏(new) -第四天
- USACO之Section1.1.3 Friday the Thirteenth
- 数据库迁移之从oracle 到 MySQL
- [Leetcode] 157. Read N Characters Given Read4 解题报告
- openssl 错误处理
- 一些有趣的算法题收集-Category
- UESTC 1639 云中谁寄锦书来?雁字回时,月满西楼。 Dijkstra拓展
- Shell中的字符串处理
- 语音控制AR.Drone的安卓上实现
- 在NanoPi-NEO上直接编译 LIVE555