-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.cpp
More file actions
34 lines (33 loc) · 701 Bytes
/
time.cpp
File metadata and controls
34 lines (33 loc) · 701 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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
size_t found;
int hours;
string time;
string newtime;
cin >> time;
found=time.find("AM");
newtime=time.substr(0,8);
hours=atoi((time.substr(0,2)).c_str());
if(found != string::npos) {
if(hours == 12) {
hours=0;
}
} else {
if(hours != 12) {
hours=hours+12;
}
}
if(hours < 10) {
newtime=newtime.replace(0,1,"0");
newtime=newtime.replace(1,1,to_string(hours));
} else {
newtime=newtime.replace(0,2,to_string(hours));
}
cout << newtime;
return 0;
}