问题链接:POJ NOI0113-02 不吉利日期。
原题出处:PKU2723
不吉利日期。
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
-
在国外,每月的13号和每周的星期5都是不吉利的。特别是当13号那天恰好是星期5时,更不吉利。已知某年的一月一日是星期w,并且这一年一定不是闰年,求出这一年所有13号那天是星期5的月份,按从小到大的顺序输出月份数字。(w=1..7)
- 输入
- 输入有一行,即一月一日星期几(w)。(1 <= w <= 7)
- 输出
- 输出有一到多行,每行一个月份,表示该月的13日是星期五。
- 样例输入
-
7
- 样例输出
-
1 10
- 提示
- 1、3、5、7、8、10、12月各有31天
4、6、9、11月各有30天
2月有28天 - 来源
- 计算概论化学学院期末考试
问题分析
这是一个日期计算的问题。
程序说明
(略)。
AC的C++语言程序:
#include <iostream> using namespace std; const int DAYS = 7; const int N = 13; enum DAY {MON=1, TUE, WED, THU, FRI, SAT, SUN}; int days[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int w, day; cin >> w; for(int i=1; i<=12; i++) { day = (w - 1 + N) % DAYS; if(day == FRI) cout << i << endl; w = (w + days[i-1]) % DAYS; } return 0; }