Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // hh to HH
- #include <iostream>
- #include <string>
- std::string PM(std::string);
- std::string AM(std::string);
- int main() {
- std::string hhTime, HHtime;
- getline(std::cin, hhTime);
- if (hhTime[8] == 'P')
- HHtime = PM(hhTime.substr(0, 8));
- else HHtime = AM(hhTime.substr(0, 8));
- std::cout << HHtime << std::endl;
- return 0;
- }
- std::string PM(std::string hhTime) {
- std::string shour = hhTime.substr(0, 2);
- if (shour != "12") {
- int ihour = std::stoi(shour) + 12;
- hhTime.replace(0, 2, std::to_string(ihour));
- }
- return hhTime;
- }
- std::string AM(std::string hhTime) {
- std::string shour = hhTime.substr(0, 2);
- if (shour == "12") {
- hhTime.replace(0, 2, "00");
- }
- return hhTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment