Sgu 115
|
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB
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 M. N 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 |
||||||
|
1 #pragma comment(linker,"/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <vector> 4 #include <cmath> 5 #include <queue> 6 #include <set> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 #define INF 0x7fffffff 12 #define mod 1000000007 13 #define ll long long 14 #define maxn 100025 15 #define pi acos(-1.0) 16 int n, m, d; 17 int f [] = { 0, 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 18 int main(){ 19 for (int i = 1; i <= 12; i++)f[i] += f[i - 1]; 20 int flag = 1; 21 scanf("%d%d", &d, &m); 22 if (m <= 0 || m > 12 || d <= 0 || d > 31)flag = 0; 23 if (m == 2 && d > 28 || ((m == 4 || m == 6 || m == 9 || m == 11) && d > 30))flag = 0; 24 printf(flag?"%d\n":"Impossible\n", (d + f[m]-1)%7+1); 25 return 0; 26 }
浙公网安备 33010602011771号