-
Notifications
You must be signed in to change notification settings - Fork 47
/
TimeConversion
53 lines (44 loc) · 956 Bytes
/
TimeConversion
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
// https://www.hackerrank.com/challenges/time-conversion/problem
#include <bits/stdc++.h>
using namespace std;
int main()
{
string time, final;
int chour;
cin >> time;
string twodig = time.substr(0, 2);
int hour = stoi(twodig);
if (hour != 12)
{
if (time[8] != 'A')
{
chour = hour + 12;
final = to_string(chour);
time.replace(0, 2, final);
time.resize(8);
cout << time;
}
else
{
time.resize(8);
cout << time;
}
}
else if (hour = 12)
{
if (time[8] != 'A')
{
time.resize(8);
cout << time;
}
else if (time[8] = 'A')
{
string zero = "00";
// final = to_string(zero);
time.replace(0, 2, zero);
time.resize(8);
cout << time;
}
}
return 0;
}