SGU 115 Calendar (模拟)

来源:互联网 发布:打开淘宝网 编辑:程序博客网 时间:2024/04/30 06:50

time limit per test: 0.5 sec. 
memory limit per test: 4096 KB

http://acm.sgu.ru/problem.php?contest=0&problem=115

First year of new millenium is gone away. In commemoration of it write a program that finds the name of the day of the week for any date in 2001.

Input

Input is a line with two positive integer numbers N and M, where N is a day number in month MN and M is not more than 100.

Output

Write current number of the day of the week for given date (Monday – number 1, … , Sunday – number 7) or phrase “Impossible” if such date does not exist.

Sample Input

21 10

Sample Output

7


water.


完整代码:

/*15ms,839KB*/#include<cstdio>const int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int sum[20];int main(void){for (int i = 1; i <= 12; ++i)sum[i] = sum[i - 1] + day[i];int n, m;scanf("%d%d", &n, &m);if (m > 12 || n > day[m])puts("Impossible");else{int ans = (sum[m - 1] + n) % 7;printf("%d", ans ? ans : 7);}return 0;}