[URI Online Judge] – 1047 – Game Time with Minutes

Read the start time and end time of a game, in hours and minutes (initial hour, initial minute, final hour, final minute). Then print the duration of the game, knowing that the game can begin in a day and finish in another day,

Obs.: With a maximum game time of 24 hours and the minimum game time of 1 minute.

Input

Four integer numbers representing the start and end time of the game.

Output

Print the duration of the game in hours and minutes, in this format: “O JOGO DUROU XXX HORA(S) E YYY MINUTO(S)” . Which means: the game lasted XXX hour(s) and YYY minutes.

Sample Input Sample Output
7 8 9 10 O JOGO DUROU 2 HORA(S) E 2 MINUTO(S)
7 7 7 7 O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)
7 10 8 9 O JOGO DUROU 0 HORA(S) E 59 MINUTO(S)

Solution:

#include <cstdio>
int main(){
 int hi, mi, hf, mf, mr, hr;
 scanf("%d %d %d %d", &hi, &mi, &hf, &mf);
hr = hf - hi;
 if (hf - hi < 0)
 hr = 24 + hf - hi;
mr = mf - mi;
 if (mf - mi < 0){
 mr = 60 + mf - mi;
 hr--;
 }
if (hf == hi && mf == mi)
 printf("O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)\n");
 else
 printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", hr, mr);
 return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s