-
Notifications
You must be signed in to change notification settings - Fork 138
/
Solution.cpp
130 lines (122 loc) Β· 3.08 KB
/
Solution.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string timeToString(int n) {
string hour;
switch (n) {
case 0:
hour = "zero";
case 1:
hour = "one";
break;
case 2:
hour = "two";
break;
case 3:
hour = "three";
break;
case 4:
hour = "four";
break;
case 5:
hour = "five";
break;
case 6:
hour = "six";
break;
case 7:
hour = "seven";
break;
case 8:
hour = "eight";
break;
case 9:
hour = "nine";
break;
case 10:
hour = "ten";
break;
case 11:
hour = "eleven";
break;
case 12:
hour = "twelve";
break;
case 13:
hour = "thirteen";
break;
case 14:
hour = "fourteen";
break;
case 15:
hour = "fifteen";
break;
case 16:
hour = "sixteen";
break;
case 17:
hour = "seventeen";
break;
case 18:
hour = "eighteen";
break;
case 19:
hour = "nineteen";
break;
case 20:
hour = "twenty";
break;
case 30:
hour = "thirty";
break;
case 40:
hour = "forty";
break;
case 50:
hour = "fifty";
break;
default:
hour = "undefined";
break;
}
return hour;
}
int main() {
string result;
int hour;
cin >> hour;
int minute;
cin >> minute;
if (minute == 0) {
result = timeToString(hour) + " o' clock";
} else if (minute == 1) {
result = "one minute past " + timeToString(hour);
} else if (minute == 59) {
result = "one minute to " + timeToString(hour);
} else if (minute == 15) {
result = "quarter past " + timeToString(hour);
} else if (minute == 45) {
result = "quarter to " + timeToString(hour+1);
} else if (minute == 30) {
result = "half past " + timeToString(hour);
} else if (minute > 0 && minute < 30) {
if (timeToString(minute) == "undefined") {
result = timeToString((minute/10)*10) + " " +
timeToString(minute % 10) + " minutes past " + timeToString(hour);
} else {
result = timeToString(minute) + " minutes past " + timeToString(hour);
}
} else if (minute > 30 ) {
if (timeToString(60 - minute) == "undefined") {
result = timeToString(((60 - minute) / 10) * 10) + " " +
timeToString((60 - minute) % 10) + " minutes to " + timeToString(hour+1);
} else {
result = timeToString(60 - minute) + " minutes to " + timeToString(hour+1);
}
}
cout << result;
return 0;
}