forked from DedSecInside/Awesome-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
The Time in Words.cpp
93 lines (72 loc) · 1.56 KB
/
The Time in Words.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
#include <bits/stdc++.h>
using namespace std;
// Complete the timeInWords function below.
string timeInWords(int h, int m) {
vector<string> numbers = {
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
"twenty one",
"twenty two",
"twenty three",
"twenty four",
"twenty five",
"twenty six",
"twenty seven",
"twenty eight",
"twenty nine"
};
if(m==0){
return numbers[h] + " o' clock";
}
else if(m==1){
return "one minute past " + numbers[h];
}
else if(m==15){
return "quarter past " + numbers[h];
}
else if(m==30){
return "half past " + numbers[h];
}
else if(m==45){
return "quarter to " + numbers[(h%12)+1];
}
else if(m<30){
return numbers[m] + " minutes past " + numbers[h];
}
else{
return numbers[60-m] + " minutes to " + numbers[(h%12)+1];
}
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int h;
cin >> h;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int m;
cin >> m;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string result = timeInWords(h, m);
fout << result << "\n";
fout.close();
return 0;
}