SGU - 115 Calendar

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 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 int day[105][105];
 8 
 9 int suan(int x)
10 {
11     x++;
12     if(x>7)
13         x=1;
14     return x;
15 }
16 
17 int main()
18 {
19     day[1][1]=1;
20     for(int i=1;i<13;i++)
21     {
22         if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
23         {
24             if(i!=0&&i!=3&&i!=8)
25                 day[i][1]=suan(day[i-1][30]);
26             if(i==3)
27                 day[i][1]=suan(day[i-1][28]);
28             if(i==8)
29                 day[i][1]=suan(day[i-1][31]);
30             for(int j=2;j<=31;j++)
31                 day[i][j]=suan(day[i][j-1]);
32         }
33         else
34         {
35             if(i==2)
36             {
37                 day[i][1]=suan(day[i-1][31]);
38                 for(int j=2;j<=28;j++)
39                     day[i][j]=suan(day[i][j-1]);                
40             }
41             else
42             {
43                 day[i][1]=suan(day[i-1][31]);
44                 for(int j=2;j<=30;j++)
45                     day[i][j]=suan(day[i][j-1]);
46             }
47         }
48     }
49     int n,m;
50     while(~scanf("%d%d",&n,&m))
51     {
52         if(day[m][n]>0)
53             printf("%d\n",day[m][n]);
54             else
55                 printf("Impossible\n");
56     }
57     
58     
59     return 0;
60 }

 

转载于:https://www.cnblogs.com/xibeiw/p/7325198.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值