Time Conversion

 avatar
ishan
c_cpp
10 days ago
959 B
3
Indexable
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int tc ;
    cin >> tc ;

    while(tc --)
    {
        string time , s ;
        cin >> time >> s ;

        int temp ;
        if(s[0] == 'A')
        {
            temp = (10 * (time[0] - '0')) + time[1] - '0' ;
            if(temp == 12)
            {
                cout << "00" << time[2] << time[3] << time[4] << endl ;
            }
            else
            {
                cout << time << endl ;
            }
        }
        else
        {
            temp = (10 * (time[0] - '0')) + time[1] - '0' ;
            if(temp == 12)
            {
                cout << time << endl ;
            }
            else
            {
                cout << 12 + temp << time[2] << time[3] << time[4] << endl ;
            }
        }
    }
}
Editor is loading...
Leave a Comment