题目
2008年上海交大计算机上机题
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 6 int ISYEAP(int x){ 7 if((x%100!=0 && x%4 == 0) ||(x % 400 == 0) ) return 1; 8 else return 0; 9 } 10 11 int dayOfMonth[13][2] = { 12 0,0, 13 31,31, 14 28,29, 15 31,31, 16 30,30, 17 31,31, 18 30,30, 19 31,31, 20 31,31, 21 30,30, 22 31,31, 23 30,30, 24 31,31 25 }; 26 27 typedef struct Date{ 28 int Day; 29 int Month; 30 int Year; 31 void nextDay(){ 32 Day++; 33 if(Day > dayOfMonth[Month][ISYEAP(Year)]){ 34 Day = 1; 35 Month++; 36 if(Month > 12){ 37 Month = 1; 38 Year++; 39 } 40 } 41 } 42 }Date; 43 44 char monthName[13][10] = { 45 "", 46 "January", 47 "February", 48 "March", 49 "April", 50 "May", 51 "June", 52 "July", 53 "August", 54 "September", 55 "October", 56 "November", 57 "December" 58 }; 59 char dayName[7][10] = { 60 "Sunday", 61 "Monday", 62 "Tuesday", 63 "Wednesday", 64 "Thursday", 65 "Friday", 66 "Saturday" 67 }; 68 int buf[3001][13][32]; 69 70 int main(){ 71 Date tmp; 72 tmp.Year = 0; 73 tmp.Month = 1; 74 tmp.Day = 1; 75 int cnt = 0; 76 while(tmp.Year != 3001){ 77 buf[tmp.Year][tmp.Month][tmp.Day] = cnt; 78 tmp.nextDay(); 79 cnt++; 80 } 81 int d,m,y; 82 char str[10]; 83 while(scanf("%d%s%d",&d,&str,&y) != EOF){ 84 for(int i = 1;i <= 12;i++){ 85 if(strcmp(str,monthName[i]) == 0){ 86 m = i; 87 break; 88 } 89 } 90 int days = (abs (buf[y][m][d] - buf[2021][3][2]) ); 91 days = (days + 2 ) % 7; 92 printf("%s ",dayName[days ]); 93 } 94 return 0; 95 }