Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <cstdlib>
  3. #include <string>
  4. using namespace std;
  5.  
  6. /*
  7. * Complete the timeConversion function below.
  8. */
  9. string timeConversion(string s) {
  10. /*
  11. * Write your code here.
  12. */
  13.  
  14. string a;
  15. a = s.at(0);
  16.  
  17. string b;
  18. b = s.at(1);
  19.  
  20. string aorp;
  21. aorp = s.at(s.size()-2);
  22.  
  23. string c = a + b;
  24.  
  25. int number = atoi (c.c_str());
  26.  
  27. string out;
  28.  
  29. if (aorp == "P" && number != 12)
  30. {
  31. number = number + 12;
  32.  
  33. }
  34. else if (to_string(number).size() < 10)
  35. {
  36. out = "0";
  37.  
  38. }
  39.  
  40.  
  41. out = out + to_string(number);
  42.  
  43. for (int i = 2 ; i < s.size() -2; i = i +1)
  44. {
  45. out = out + s.at(i);
  46. }
  47.  
  48.  
  49. return out;
  50.  
  51.  
  52. }
  53.  
  54. int main()
  55. {
  56. ofstream fout(getenv("OUTPUT_PATH"));
  57.  
  58. string s;
  59. getline(cin, s);
  60.  
  61. string result = timeConversion(s);
  62.  
  63. fout << result << "\n";
  64.  
  65. fout.close();
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement