Codechef Problems : Happy New Year! (NEWYEAR)

 Problem Statement: 

Currently, it is X:00 hours on December 31st and you are wondering how many hours are left till midnight.

For the purposes of this problem, we use a 24 hour system. So, X can range from 0 to 23, and you need to tell the number of hours left till 00:00 of the next day.

Input Format

  • The first and only line of input contains a single integer X.

Output Format

For each test case, output on a new line the number of hours left till midnight

Constraints

  • 0X23

Solution: 

Given, X : current time in hour on December 31st. 
To Find: Remaining time for New year i.e., 0 hour of the next day 

we know there are 24 hours in a day and present time is X hour 
so time remaining for 0 hour next day is (24 - X) 

Code Solution: 

#include <bits/stdc++.h>

using namespace std;

int main() {
    int x;
    cin >> x;

    cout << 24 - x << endl;
    return 0;
}

Comments

Popular posts from this blog

Codechef Problems: Triangles (TRIANGLE7)

Codechef problems : New Year Resolution (NYRES)

Codechef Problems: Selling Sandwiches (SANDWSHOP)