Algorithm


Problem Name: beecrowd | 2057

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2057

Time Zone

 

By Neilor Tonin, URI BR Brazil

Timelimit: 1

Paul and Peter have made a long journey since they left Brazil to compete in the ICPC World Finals, in Phuket, Thailand. They noticed that in each place where they stopped, they had to adjust their watches because of the time zone.

This way, to plan for upcoming trips, they asked you to create a mobile application that, given the departure time, travel time and the destination time zone with respect to the origin, you have to inform the time of arrival of each flight in the destination.

For example, if they left a place at 10 am for a 4 hour journey to a destination that is on the east, in a time zone with an extra hour with respect to the time zone of the starting point, the arrival time will be 10 hours + 4 hours + 1 hour (due de time zone), i.e. they will arrive at 15 hours. Note that if the calculated time is 24, its program should print 0 (zero).

 

Input

 

The input contains 3 integers: S (0 ≤ S ≤ 23), T (1 ≤ T ≤ 12) y F (-5 ≤ F ≤ 5), separated by a space, respectively indicating the time of departure, the travel time and destination time zone with respect to the origin.

 

Output

 

Print an integer that indicates the local time specified in destination, as the examples below.

 

 

 

Input Samples Output Samples

10 7 3

20

 

 

 

22 6 -2

2

 

0 3 -4

23

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int a, b, c, x;

    scanf("%i %i %i", &a, &b, &c);

    x=a+b+c;

    if (x  <  0)
        x=24+x;

    else if (x < 24)
        x=x;

    else if (x==24)
        x=0;

    else if (x > 24)
        x=x-24;

    printf("%i\n", x);

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 7 3

Output

x
+
cmd
20

#2 Code Example with C++ Programming

Code - C++ Programming


#include<stdio.h>
int main()
{
    int a,b,c,now,then;
    scanf("%d %d %d",&a,&b,&c);
    if(a==0)a=24;
    now=a+b;
    then=now+c;
    if(then>=24)
        printf("%d\n",then-24);
    else
        printf("%d\n",then);
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 7 3

Output

x
+
cmd
20

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
var [S,T,F] = (prompt("Digite os Valores").split(" ")).map(Number)
var final = (S + T + F)
if(S==0){
    S=24
}
var final = (S + T + F)
if (final >= 24){
    final = final - 24
    console.log(final)
}else if (final==24 && final==0){
    console.log(final)
}else{
    console.log(final)
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 7 3

Output

x
+
cmd
20

#4 Code Example with Python Programming

Code - Python Programming


S,T,F = map(int,input().split())
if S==0:
    S=24
chegada= S+T+F
if chegada>24:
    chegada=chegada-24
    print(chegada)
elif chegada==24:
    chegada=0
    print(chegada)
else:
    print(chegada)
Copy The Code & Try With Live Editor

Input

x
+
cmd
10 7 3

Output

x
+
cmd
20
Advertisements

Demonstration


Previous
#2031 Beecrowd Online Judge Solution 2031 Rock, Paper, Airstrike Solution in C, C++, Java, Js and Python
Next
#2058 Beecrowd Online Judge Solution 2058 Triangles and Regular Polygons Solution in C, C++, Java, Js and Python