For better understanding refer YouTube Tutorial Video
CODE:
/***SOLUTION BY CODING DEMONS***/
#include<bits/stdc++.h>using namespace std;
int main(){
int n;               //for hourstring s;           //for restcin>>n;   cin>>s;   
//AM or PM is present at 6th positionif(s[6]=='P'){                                               if(n==12){       //for PM cout<<n; }     else {   
//to convert in 24 hr format n=n+12;   cout<<n; }  }     else {         //for AMif(n==12){ cout<<"00";}  else {   cout<<"0"<<n; //as n will print single digit only}        }       //no need to print AM/PM in 24hr formats.erase(6);                        cout<<s;                                      //print the remaining string
return 0;}
/***********END***********/
/***SOLUTION BY CODING DEMONS***/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;               //for hour
string s;           //for rest
cin>>n;   
cin>>s;   
//AM or PM is present at 6th position
if(s[6]=='P'){      
if(n==12){       //for PM
 cout<<n; 
}     
else {   
//to convert in 24 hr format
 n=n+12;  
 cout<<n; 
}  
}     
else {         //for AM
if(n==12){
 cout<<"00";
}  
else {  
 cout<<"0"<<n;
 //as n will print single digit only
}        
}   
//no need to print AM/PM in 24hr format
s.erase(6); 
cout<<s;                                      //print the remaining string
return 0;
}
/***********END***********/

0 Comments