首页 > 代码库 > SGU - 115 Calendar
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 }
SGU - 115 Calendar
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。