fueanta

hh -> HH

Feb 20th, 2017
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // hh to HH
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. std::string PM(std::string);
  7. std::string AM(std::string);
  8.  
  9. int main() {
  10.     std::string hhTime, HHtime;
  11.     getline(std::cin, hhTime);
  12.  
  13.     if (hhTime[8] == 'P')
  14.         HHtime = PM(hhTime.substr(0, 8));
  15.     else HHtime = AM(hhTime.substr(0, 8));
  16.  
  17.     std::cout << HHtime << std::endl;
  18.     return 0;
  19. }
  20.  
  21. std::string PM(std::string hhTime) {
  22.     std::string shour = hhTime.substr(0, 2);
  23.     if (shour != "12") {
  24.         int ihour = std::stoi(shour) + 12;
  25.         hhTime.replace(0, 2, std::to_string(ihour));
  26.     }
  27.     return hhTime;
  28. }
  29.  
  30. std::string AM(std::string hhTime) {
  31.     std::string shour = hhTime.substr(0, 2);
  32.     if (shour == "12") {
  33.         hhTime.replace(0, 2, "00");
  34.     }
  35.     return hhTime;
  36. }
RAW Paste Data