• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

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

Author : Michael R. Mirzayanov
Resource : PhTL #1 Training Contests
Date : January 2002
 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 }
View Code
posted @ 2014-02-03 19:46  HaibaraAi  阅读(79)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3