forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimedate.cpp
50 lines (42 loc) · 753 Bytes
/
timedate.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
47
48
49
50
#include<iostream>
#include<stdio.h>
#include <cstdlib>
#include <sstream>
#include <string>
using namespace std;
using std::string;
string timeconversion(string s){
string sub = s.substr(8,9);
if(sub=="pm"||sub=="PM"){
string up;
int update_hour;
string hour = s.substr(0,2);
if(hour=="12"){
s.erase(8,9);
return s;
}
else{
update_hour= atoi(hour.c_str());
update_hour+=12;
stringstream ss;
ss << update_hour;
ss >> up;
s.replace(0,2,up);
s.erase(8,9);
return s;
}
}else{
string hour = s.substr(0,2);
if(hour=="12"){
s.replace(0,2,"00");
}
s.erase(8,9);
return s;
}
}
int main(){
string time="";
cin>>time;
string result = timeconversion(time);
cout<<result;
}