You are viewing a single comment's thread. Return to all comments →
using namespace std;
/* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */
string timeConversion(string s) { string period = s.substr(8, 2); // Extract AM or PM string hour_str = s.substr(0, 2); int hour = stoi(hour_str); string remaining = s.substr(2, 6); // Remaining part after hour (":MM:SS")
if (period == "AM") { if (hour == 12) { hour_str = "00"; } } else { // PM case if (hour != 12) { hour += 12; hour_str = to_string(hour); } } return hour_str + remaining;
}
int main() { ofstream fout(getenv("OUTPUT_PATH"));
string s; getline(cin, s); string result = timeConversion(s); fout << result << "\n"; fout.close(); 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 →
include
using namespace std;
/* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */
string timeConversion(string s) { string period = s.substr(8, 2); // Extract AM or PM string hour_str = s.substr(0, 2); int hour = stoi(hour_str); string remaining = s.substr(2, 6); // Remaining part after hour (":MM:SS")
}
int main() { ofstream fout(getenv("OUTPUT_PATH"));
}