【USACO1.1.3】Friday the Thirteenth

Friday the Thirteenth

Is Friday the 13th really an unusual event?

That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is positive and will not exceed 400.

Note that the start year is NINETEEN HUNDRED, not 1990.

There are few facts you need to know before you can solve this problem:

Do not use any built-in date functions in your computer language.

Don’t just precompute the answers, either, please.

PROGRAM NAME: fridayINPUT FORMATOne line with the integer N.SAMPLE INPUT (file friday.in)20OUTPUT FORMATSeven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, …, Friday.SAMPLE OUTPUT (file friday.out)36 33 34 33 35 35 34

从一个时间开始到另一个时间内 每个月的13号在每一周的周几的次数 从周日开始一次输出

简单模拟 日期的模拟绝对最大的弱项。。。。

/*ID: Alpha AugurPROG: fridayLANG: C++*/#include <iostream>#include <string>#include <cstdio>#include <cstring>#include <map>using namespace std;int days[12] = {31,31,28,31,30,31,30,31,31,30,31,30};int ans[7];int main(){freopen("friday.in", "r", stdin);freopen("friday.out", "w", stdout);int n, last = 3;cin >> n;for(int year = 1900; year < 1900+n; ++year){if(year%400==0 || (year%100!=0 && year%4==0)){days[2] = 29;}for(int month = 0; month < 12; ++month){last=(last+days[month])%7;ans[last]++;}days[2] = 28;}for(int i = 0; i < 6; ++i){cout << ans[(i+6)%7] << " ";}cout << ans[5] << endl;return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,属于自己的不要放弃,已经失去的留作回忆。

【USACO1.1.3】Friday the Thirteenth

相关文章:

你感兴趣的文章:

标签云: