Solution of Time Conversion (Hackerrank)

Hi all!!

Here's my solution to the problem 'Time Conversion' on Hackerrank.

Problem link: https://www.hackerrank.com/challenges/time-conversion/


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;

string timeconversion(string s){
    if(s[8]=='A'){
        s.erase(8,2);
        if(s[0]=='1'&&s[1]=='2'){
            s[0]='0';
            s[1]='0';
        }
        return s;
    }
    else{
        s.erase(8,2);
        s[0]+=1;
        s[1]+=2;
        if(s[0]=='2'&&s[1]=='4'){
            s[0]='1';
            s[1]='2';
        }
        return s;
    }
}

int32_t main()
{
    string s;
    cin>>s;
    string t = timeconversion(s);
    cout<<t<<'\n';
    return 0;
}


Comments

Popular posts from this blog

Solution of 'The Two Dishes' (Codechef)

Solution of 'Tom Riddle's Diary' (Codeforces)

Solution of 'Less or Equal' (Codeforces)