forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusyschedule.cpp
72 lines (59 loc) · 1.34 KB
/
busyschedule.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
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct timestruct {
int hours = 0;
int minutes = 0;
char c = 'a';
};
bool compare(timestruct t1, timestruct t2) {
// Check AM PM
if(t1.c < t2.c) {
return true;
}
if(t1.c > t2.c) {
return false;
}
int t1comb = t1.hours * 100 + t1.minutes;
int t2comb = t2.hours * 100 + t2.minutes;
return t1comb < t2comb;
}
int main() {
int n;
while(cin >> n && n != 0) {
vector<timestruct> v;
for(int i = 0; i < n; i++) {
char trash1;
string trash2;
timestruct t;
cin >> t.hours;
cin >> trash1;
cin >> t.minutes;
cin >> t.c;
cin >> trash2;
if(t.hours == 12) {
t.hours -= 12;
}
v.push_back(t);
}
sort(v.begin(), v.end(), compare);
for(auto t : v) {
if(t.hours == 0) {
cout << 12;
}
else {
cout << t.hours;
}
cout << ":";
if(t.minutes < 10) {
cout << "0";
}
cout << t.minutes;
cout << ' ';
cout << t.c;
cout << ".m." << endl;
}
cout << endl;
}
}