URI Online Judge | 1047
Tempo de Jogo com Minutos
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1
Leia a hora inicial, minuto inicial, hora final e minuto final de um jogo. A seguir calcule a duração do jogo.
Obs: O jogo tem duração mínima de um (1) minuto e duração máxima de 24 horas.
Entrada
Quatro números inteiros representando a hora de início e fim do jogo.
Saída
Mostre a seguinte mensagem: “O JOGO DUROU XXX HORA(S) E YYY MINUTO(S)” .
URI Online Judge | 1047
Game Time with Minutes
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
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.
#include <stdio.h>
int main()
{
int Hora_inicio, final, minuto_inicio, minuto_final, tempo_horatotal, tempo_minutototal;
scanf("%d %d %d %d", &Hora_inicio, &minuto_inicio, &final, &minuto_final);
tempo_horatotal = final - Hora_inicio;
if (tempo_horatotal < 0)
{
tempo_horatotal = 24 + (final - Hora_inicio);
}
tempo_minutototal = minuto_final - minuto_inicio;
if (tempo_minutototal < 0)
{
tempo_minutototal = 60 + (minuto_final - minuto_inicio);
tempo_horatotal--;
}
if (Hora_inicio == final && minuto_inicio == minuto_final)
{
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", tempo_horatotal, tempo_minutototal);
return 0;
}
Nenhum comentário:
Postar um comentário