-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1340.cc
63 lines (51 loc) · 1.65 KB
/
P1340.cc
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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
constexpr int DAYS[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; // sum of days of months
constexpr int YEAR = 525600; // minutes
constexpr int DAY = 1440; // minutes
constexpr bool is_leap(int year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
constexpr int to_days(int year, int month) {
if(is_leap(year) && month > 2) return DAYS[month-1] + 1;
else return DAYS[month-1];
}
int numeric_month(const string& month) {
if (month == "January") return 1;
else if (month == "February") return 2;
else if (month == "March") return 3;
else if (month == "April") return 4;
else if (month == "May") return 5;
else if (month == "June") return 6;
else if (month == "July") return 7;
else if (month == "August") return 8;
else if (month == "September") return 9;
else if (month == "October") return 10;
else if (month == "November") return 11;
else if (month == "December") return 12;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
string month;
int day = 0;
int year = 0;
int hour = 0;
int minute = 0;
cin >> month >> day;
cin.ignore(numeric_limits<streamsize>::max(), ',');
cin >> year >> hour;
cin.ignore(numeric_limits<streamsize>::max(), ':');
cin >> minute;
int sum = 0; // in minutes
sum += to_days(year, numeric_month(month)) * DAY;
sum += (day-1) * DAY;
sum += hour * 60;
sum += minute;
double divisor = YEAR;
if(is_leap(year)) divisor += DAY;
cout << (sum*100) / divisor << endl;
}