URI Online Judge Solution 1047 Game Time with Minutes using C Programming Language.
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,
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.
Input Sample | Output Sample |
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)
|
URI 1047 Solution in C :
#include <stdio.h>
int main() {
int h1, m1, h2, m2, h,m;
scanf("%d %d %d %d", &h1, &m1, &h2, &m2);
h = h2 - h1;
if (h < 0)
{
h = 24 + (h2 - h1);
}
m = m2 - m1;
if (m < 0)
{
m = 60 + (m2 - m1);
h--;
}
if (h2 == h1 && m2 == m1)
{
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", h, m);
return 0;
}
//Uri 1047 solution (wrong error 5% sliver)
ReplyDelete#include
int main()
{
int s_hr,s_min,e_hr,e_min,d_hr,d_min;
scanf("%d%d%d%d",&s_hr,&s_min,&e_hr,&e_min);
d_hr=e_hr-s_hr;
if(d_hr<0)
{
d_hr=24+d_hr;
}
d_min=e_min-s_min;
if(d_min<0)
{
d_min=60+d_min;
d_hr--;
if(d_hr<0)
{
d_hr=24+d_hr;
}
}
if(d_hr==0&&d_min==0)
{
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",d_hr,d_min);
}
return 0;
}//end of line