You are viewing a single comment's thread. Return to all comments →
int main() { string time; cin >> time; string output = time.substr(0, 8); string ampm = time.substr(time.size() - 2); string hourString = time.substr(0, 2); if (ampm == "PM" && hourString != "12") { int hour = stoi(hourString); hour = (hour + 12) % 24; stringstream ss; ss << hour; output[0] = ss.str()[0]; output[1] = ss.str()[1]; } else if (ampm == "AM" && hourString == "12") { output[0] = output[1] = '0'; } cout << output; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →