-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathTimeConversion.cpp
More file actions
53 lines (45 loc) · 899 Bytes
/
TimeConversion.cpp
File metadata and controls
53 lines (45 loc) · 899 Bytes
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
#include <iostream>
using namespace std;
void print24(string str)
{
int h1 = (int)str[1] -'0';
int h2 = (int)str[0] -'0';
int hh = (h2 * 10 + h1);
if (str[8] == 'A')
{
if (hh == 12)
{
cout << "00";
for (int i=2; i <= 7; i++)
cout << str[i];
}
else
{
for (int i=0; i <= 7; i++)
cout << str[i];
}
}
else
{
if (hh == 12)
{
cout << "12";
for (int i=2; i <= 7; i++)
cout << str[i];
}
else
{
hh = hh + 12;
cout << hh;
for (int i=2; i <= 7; i++)
cout << str[i];
}
}
}
int main()
{
string str;
cin >> str;
print24(str);
return 0;
}