Advertisement
Ankit_132

C

Mar 28th, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll     long long
  5. #define ff     first
  6. #define ss     second
  7. #define pb     push_back
  8.  
  9. int main()
  10. {
  11.     int test;
  12.     cin>>test;
  13.  
  14.     while(test--){
  15.         string s;
  16.         cin>>s;
  17.  
  18.         int h = (s[0]-'0')*10 + (s[1]-'0');
  19.  
  20.         int f = 0;
  21.  
  22.         if(h >= 12)     h-=12, f=1;
  23.         if(h == 0)      h=12;
  24.  
  25.         string hh = to_string(h);
  26.  
  27.         if(hh.size() == 1)      hh = "0"+hh;
  28.  
  29.         if(f)
  30.             cout<<hh<<":"<<s[3]<<s[4]<<" PM\n";
  31.         else
  32.             cout<<hh<<":"<<s[3]<<s[4]<<" AM\n";
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement