-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime-conversion.cpp
46 lines (43 loc) · 977 Bytes
/
time-conversion.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
#include <iostream>
using namespace std;
int main () {
string s;
cin >> s;
string leftStr;
string result;
bool lessThanOne = false;
int left = s[0] - '0';
if(left == 0)
lessThanOne = true;
int len = s.size();
char PMorAM = s[len-2];
if(PMorAM == 'P')
{
if(s[0] == '1' && s[1] == '2')
leftStr = "12";
else if(lessThanOne)
leftStr = to_string(s[1] - '0' + 12);
else {
int num1 = (s[0] - '0');
int num2 = (s[1] - '0');
leftStr = to_string((num1*10)+num2 + 12);
}
}
else
{
if(s[0] == '1' && s[1] == '2')
leftStr = "00";
else
{
int num1 = (s[0] - '0');
if(num1 == 0)
leftStr='0';
int num2 = (s[1] - '0');
leftStr += to_string((num1*10)+num2);
}
}
result += leftStr;
for(int i = 2; i < len - 2; ++i)
result+=s[i];
cout << result;
}