-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.cpp
148 lines (133 loc) · 1.89 KB
/
Date.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <cstdio>
#include <stdio.h>
#include <iostream>
using namespace std;
int isYear(int x)
{
if ((x % 100 != 0 && x % 4 == 0) || (x % 400 == 0))
return 1;
else
return 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 day;
int month;
int year;
void nextDay()
{
day++;
if (day > dayOfMonth[month][isYear(year)])
{
day = 1;
month++;
if (month > 12)
{
month = 1;
year++;
}
}
}
};
int buf[3001][13][32];
string monthName[13] =
{
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
string weekName[8]
{
"",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
int abs(int x)
{
return x < 0 ? -x : x;
}
int main()
{
Date temp;
int cnt = 0;
temp.day = 1;
temp.month = 1;
temp.year = 0;
while (temp.year != 3001)
{
buf[temp.year][temp.month][temp.day] = cnt;
temp.nextDay();
cnt++;
}
int d1 = 2, y1 = 2019, week1 = 6;
string m1 = "March";
int d2, y2;
string m2;
int month1, month2;
while (cin >> d2 >> m2 >> y2)
{
for (int i = 1; i <= 12; i++)
{
if (m1 == monthName[i])
{
month1 = i;
//cout<<month1<<endl;
break;
}
}
for (int i = 1; i <= 12; ++i)
{
if (m2 == monthName[i])
{
month2 = i;
//cout<<month2<<endl;
break;
}
}
int targetDay = buf[y2][month2][d2];
int curDay = buf[y1][month1][d1];
//cout<<targetDay<<" "<<curDay<<endl;
long dif = targetDay - curDay;
cout << dif << endl;
if (dif >= 0)
{
int ans = ((dif % 7) + week1) % 7;
cout << weekName[ans];
} else
{
int ans=((dif+week1)%7+7);
cout<<weekName[ans];
}
}
}