-
Notifications
You must be signed in to change notification settings - Fork 8
/
TimeInWords.cpp
37 lines (36 loc) · 1.23 KB
/
TimeInWords.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
#include<bits/stdc++.h>
using namespace std;
// Complete the timeInWords function below.
void timeInWords(int h, int m)
{
string s[12]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"};
string s1[29]={"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==00)
cout<<s[h-1]<<" "<<"o' clock";
else if(m==1)
cout<<s1[m-1]<<" minute past "<<s[h-1];
else if(m>01 && m<15)
cout<<s1[m-1]<<" minutes past "<<s[h-1];
else if(m==15)
cout<<"quarter past "<<s[h-1];
else if(m>15 && m<=29)
cout<<s1[m-1]<<" minutes past "<<s[h-1];
else if(m==30)
cout<<"half past "<<s[h-1];
else if(m>30 && m<45)
cout<<s1[59-m]<<" minutes to "<<s[h];
else if(m==45)
cout<<"quarter to "<<s[h];
else
cout<<s1[59-m]<<" minutes to "<<s[h];
}
int main()
{ ios::sync_with_stdio(0);
cin.tie(0);
int h;
cin >> h;
int m;
cin >> m;
timeInWords(h,m);
return 0;
}