Wednesday, December 2, 2015

Uri problem 1046 solve

Problem :

Game Time

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read the start time and end time of a game, in hours. Then calculate the duration of the game, knowing that the game can begin in a day and finish in another day, with a maximum duration of 24 hours. The message must be printed in portuguese “O JOGO DUROU X HORA(S)” that means “THE GAME LASTED X HOUR(S)”

Input

Two integer numbers representing the start and end time of a game.

Output

Print the duration of the game as in the sample output.
Sample InputSample Output
16 2O JOGO DUROU 10 HORA(S)
0 0O JOGO DUROU 24 HORA(S)
2 16O JOGO DUROU 14 HORA(S)

Solution:

#include <stdio.h>
  
int main() {
  
    int start, end, lasted;
    scanf("%d %d",&start, &end);
    if (start >= end)
    {
    lasted=(24-start)+end;
        printf("O JOGO DUROU %d HORA(S)\n",lasted);
        }
    else if(start < end)
        {
        lasted=end - start ;
        if (lasted <= 1)
        {
    printf("O JOGO DUROU %d HORA(S)\n",lasted);
            }
        else
        {
          printf("O JOGO DUROU %d HORA(S)\n",lasted);
        }
         }
 
 
  
    return 0;
}

No comments:

Post a Comment