-
Notifications
You must be signed in to change notification settings - Fork 2
/
dayOfWeek.cpp
98 lines (83 loc) · 1.24 KB
/
dayOfWeek.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<stdio.h>
#include<string.h>
#define ISYEAP(x) x%4==0 && x % 100 !=0 || x % 400 ==0 ? 1:0
int dayofmonth[13][2]={
{0, 0},
{31, 31},
{28, 29},
{31, 31},
{30, 30},
{31, 31},
{30, 30},
{31, 31},
{31, 31},
{30, 30},
{31, 31},
{30, 30},
{31, 31}
};
struct Date{
int year;
int month;
int day;
void nextday(){
day++;
if(day> dayofmonth[month][ISYEAP(year)]){ // 若日数超过了当月最大日数
day=1;
month++; // 进入下一月
if(month>12){ // 超过12
month=1;
year++;
}
}
}
};
int buf[3001][13][32];
char monthname[13][20]={
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
char weekname[7][20]={
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
int main6()
{
Date date;
int cnt = 0;
date.year = 0;
date.month = 1;
date.day = 1;
while( date.year != 3000 ){
buf[date.year][date.month][date.day] = cnt;
date.nextday();
cnt++;
}
int y,m,d;
char s[20];
while(scanf("%d%s%d", &d, s, &y)!=EOF){
for(m=1; m<=12; m++){
if(strcmp(s, monthname[m])==0) break;
}
int days = buf[y][m][d] - buf[2012][7][16];
days+=1;
puts(weekname[(days%7 + 7) % 7]);
}
return 0;
}