USACO之Section1.1.3 Friday the Thirteenth
2017-05-28 15:46
281 查看
这道题意为:输入一个N,求从1900年1月1日到1900+n-1年12月31日
其间每个月的第13天是星期几?
输出:从星期6到5的各自的个数。
关键为:求出到1900年1月1日的天数。判断闰年。
先列出一般思路,就是先要判断年份是否为闰年,在用数组去取,每月的天数,最后取余7,得到星期。
这里不再叙述,我将采取基姆拉尔森计算公式的方法去得出星期。
基姆拉尔森计算公式:请自己百度。
关键为:遇到1,2月时将其转为13,14月,同时年份减一。
代码如下:
其间每个月的第13天是星期几?
输出:从星期6到5的各自的个数。
关键为:求出到1900年1月1日的天数。判断闰年。
先列出一般思路,就是先要判断年份是否为闰年,在用数组去取,每月的天数,最后取余7,得到星期。
这里不再叙述,我将采取基姆拉尔森计算公式的方法去得出星期。
基姆拉尔森计算公式:请自己百度。
关键为:遇到1,2月时将其转为13,14月,同时年份减一。
代码如下:
/* ID: m1519591 PROG: friday LANG: 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; }
相关文章推荐
- USACO-Friday the Thirteenth(黑色星期五)-Section1.2<3>
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- [USACO 1.1.3] Friday the Thirteenth
- USACO Section 1.1 Friday the Thirteenth
- USACO1.1.3--Friday the Thirteenth
- usaco1.1.3 Friday the Thirteenth黑色星期五
- Usaco 1.1.3 黑色星期五(Friday the Thirteenth)
- USACO Section 1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth
- USACO:Section 1.1 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth 13日星期五
- USACO1.1.3 Friday the Thirteenth (friday)
- 【USACO题库】1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3 Friday the Thirteenth
- USACO section 1.1 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO 1.1.3 Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth(黑色星期五)
- USACO-Section1.1 Friday the Thirteenth [日期]