CPP
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
#include<sstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
string timeConversion(string s) {
istringstream is(s);
int hours;
int minutes;
int seconds;
string ampm;
char colon;
is >> hours >> colon >> minutes >> colon >> seconds >> ampm;
if(is.fail()) {
return "Error: wrong format";
}
ostringstream os;
if(ampm == "PM" && hours<12){
hours += 12 ;
}
if(ampm == "PM" && hours == 12){
hours = 12 ;
}
if(ampm == "AM" && hours == 12){
hours = 00 ;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run