-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path11947.cpp
More file actions
234 lines (199 loc) · 5.03 KB
/
11947.cpp
File metadata and controls
234 lines (199 loc) · 5.03 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
#include <utility>
#include <iomanip>
#include <cctype>
using namespace std;
using namespace std::rel_ops;
// Date struct by Howard Cheng
struct Date {
int yyyy;
int mm;
int dd;
// no dates before 1753
static int const BASE_YEAR = 1753;
// Enumerated type for names of the days of the week
enum dayName {
SUN, MON, TUE, WED, THU, FRI, SAT
};
// Is a date valid
static bool validDate(int yr, int mon, int day) {
return yr >= BASE_YEAR && mon >= 1 && mon <= 12 &&
day > 0 && day <= daysIn(mon, yr);
}
bool isValid() const {
return validDate(yyyy, mm, dd);
}
// Constructor to create a specific date. If the date is invalid,
// the behaviour is undefined
Date(int yr = 1970, int mon = 1, int day = 1) {
yyyy = yr;
mm = mon;
dd = day;
}
// Returns the day of the week for this
dayName dayOfWeek() const {
int a = (14 - mm) / 12;
int y = yyyy - a;
int m = mm + 12 * a - 2;
return (dayName)((dd + y + y / 4 - y / 100 + y / 400 + 31 * m / 12) % 7);
}
// comparison operators
bool operator==(const Date &d) const {
return dd == d.dd && mm == d.mm && yyyy == d.yyyy;
}
bool operator<(const Date &d) const {
return yyyy < d.yyyy || (yyyy == d.yyyy && mm < d.mm) ||
(yyyy == d.yyyy && mm == d.mm && dd < d.dd);
}
// Returns true if yr is a leap year
static bool leapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
// number of days in this month
static int daysIn(int m, int y) {
switch (m) {
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if (leapYear(y)) {
return 29;
} else {
return 28;
}
default:
return 31;
}
}
// increment by day, month, or year
//
// Use negative argument to decrement
//
// If adding a month/year results in a date before BASE_YEAR, the result
// is undefined.
//
// If adding a month/year results in an invalid date (Feb 29 on a non-leap
// year, Feb 31, Jun 31, etc.), the results are automatically "rounded down"
// to the last valid date
// add n days to the date: complexity is about n/30 iterations
void addDay(int n = 1) {
dd += n;
while (dd > daysIn(mm, yyyy)) {
dd -= daysIn(mm, yyyy);
if (++mm > 12) {
mm = 1;
yyyy++;
}
}
while (dd < 1) {
if (--mm < 1) {
mm = 12;
yyyy--;
}
dd += daysIn(mm, yyyy);
}
}
// add n months to the date: complexity is about n/12 iterations
void addMonth(int n = 1) {
mm += n;
while (mm > 12) {
mm -= 12;
yyyy++;
}
while (mm < 1) {
mm += 12;
yyyy--;
}
if (dd > daysIn(mm, yyyy)) {
dd = daysIn(mm, yyyy);
}
}
// add n years to the date
void addYear(int n = 1) {
yyyy += n;
if (!leapYear(yyyy) && mm == 2 && dd == 29) {
dd = 28;
}
}
// number of days since 1753/01/01, including the current date
int daysFromStart() const {
int c = 0;
Date d(BASE_YEAR, 1, 1);
Date d2(d);
d2.addYear(1);
while (d2 < *this) {
c += leapYear(d.yyyy) ? 366 : 365;
d = d2;
d2.addYear(1);
}
d2 = d;
d2.addMonth(1);
while (d2 < *this) {
c += daysIn(d.mm, d.yyyy);
d = d2;
d2.addMonth(1);
}
while (d <= *this) {
d.addDay();
c++;
}
return c;
}
};
// Reads a date in yyyy/mm/dd format, assumes date is valid and in the right format
istream& operator>>(istream &is, Date &d) {
char c;
return is >> d.yyyy >> c >> d.mm >> c >> d.dd;
}
// print date in mm/dd/yyyy format
ostream& operator<< (ostream &os, const Date &d) {
char t = os.fill('0');
os << setw(2) << d.mm << '/' << setw(2) << d.dd << '/' << d.yyyy;
os.fill(t);
return os;
}
using namespace std;
int64_t counter = 1;
int64_t num;
Date date;
void solve();
string findSign(Date d);
int main() {
int64_t cases;
cin >> cases;
for (int64_t i = 0; i < cases; i++) {
solve();
}
return 0;
}
void solve() {
cin >> num;
date.yyyy = num % 10000;
num /= 10000;
date.dd = num % 100;
num /= 100;
date.mm = num % 100;
for (int64_t i = 0; i < (40 * 7); i++) {
date.addDay();
}
cout << counter++ << " " << date << " " << findSign(date) << endl;
}
string findSign(Date d) {
if ((d.dd >= 23 && d.mm == 12) || (d.dd <= 20 && d.mm == 1)) { return "capricorn"; }
if ((d.dd >= 21 && d.mm == 1) || (d.dd <= 19 && d.mm == 2)) { return "aquarius"; }
if ((d.dd >= 20 && d.mm == 2) || (d.dd <= 20 && d.mm == 3)) { return "pisces"; }
if ((d.dd >= 21 && d.mm == 3) || (d.dd <= 20 && d.mm == 4)) { return "aries"; }
if ((d.dd >= 21 && d.mm == 4) || (d.dd <= 21 && d.mm == 5)) { return "taurus"; }
if ((d.dd >= 22 && d.mm == 5) || (d.dd <= 21 && d.mm == 6)) { return "gemini"; }
if ((d.dd >= 22 && d.mm == 6) || (d.dd <= 22 && d.mm == 7)) { return "cancer"; }
if ((d.dd >= 23 && d.mm == 7) || (d.dd <= 21 && d.mm == 8)) { return "leo"; }
if ((d.dd >= 22 && d.mm == 8) || (d.dd <= 23 && d.mm == 9)) { return "virgo"; }
if ((d.dd >= 24 && d.mm == 9) || (d.dd <= 23 && d.mm == 10)) { return "libra"; }
if ((d.dd >= 24 && d.mm == 10) || (d.dd <= 22 && d.mm == 11)) { return "scorpio"; }
if ((d.dd >= 23 && d.mm == 11) || (d.dd <= 22 && d.mm == 12)) { return "sagittarius"; }
}