Time after n hours

Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

Math .

PROBLEM:

If Now time is 12 PM what time will after N hours .

  • note: time format is 24 hrs.

for example :

N = 5

O/P = 17

after 5 hours of 12 pm is 17 .

EXPLANATION:

We have given a fix time is of clock 12 pm and we have given a clock format of 24 hrs
we have to just add the time given 12 pm and what time will it be after adding we have to manage it according to 24 hrs clock format
lets take an example suppose N=5
and now time is 12 pm we have to just add it and we will found out what time it is adding 5 in 12 will give output 17

Let’s take another example N= 15
now its 12 pm after 15 hours time will be 03 am means we have just mod it from 12 and we got our output that is 03

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int k=0,p=0,tp=0,kp=0;
if(n%12==0){
k=n/12;
if(k%2==0){
cout<<“12”;
}
else cout<<“00”;
}
else{

 p=n/12;
 
 if(p%2!=0){
     kp=n%12;
     if(kp<10){
       cout<<'0';
       cout<<kp;
     }
     else{
       cout<<kp;
     }
 }
 else{
  tp=n%12;
  cout<<tp+12;
 }

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int k=0,p=0,tp=0,kp=0;
if(n%12==0){
k=n/12;
if(k%2==0){
cout<<“12”;
}
else cout<<“00”;
}
else{

 p=n/12;
 
 if(p%2!=0){
     kp=n%12;
     if(kp<10){
       cout<<'0';
       cout<<kp;
     }
     else{
       cout<<kp;
     }
 }
 else{
  tp=n%12;
  cout<<tp+12;
 }

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int k=0,p=0,tp=0,kp=0;
if(n%12==0){
k=n/12;
if(k%2==0){
cout<<“12”;
}
else cout<<“00”;
}
else{

 p=n/12;
 
 if(p%2!=0){
     kp=n%12;
     if(kp<10){
       cout<<'0';
       cout<<kp;
     }
     else{
       cout<<kp;
     }
 }
 else{
  tp=n%12;
  cout<<tp+12;
 }

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}