[URI Online Judge] – 1046 – Game Time

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 Input Sample Output
16 2 O JOGO DUROU 10 HORA(S)
0 0 O JOGO DUROU 24 HORA(S)
2 16 O JOGO DUROU 14 HORA(S)

Solution:

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

2 thoughts on “[URI Online Judge] – 1046 – Game Time

  1. What is wrong in my code? It say’s 20% error. Please let me know the problem.

    #include

    using namespace std;

    int main()
    {
    int s,e;
    scanf(“%d%d”,&s,&e);

    if(e>=12)
    {
        printf("O JOGO DUROU %d HORA(S)\n",e-s);
    }
    
    else
    {
        printf("O JOGO DUROU %d HORA(S)\n",(24-s)+e);
    }
    
    return 0;
    

    }

    Liked by 1 person

    • view your if-statement, you can not compare ‘e’ variable becoz it just the end time, but on this problem, you must calculate time interval from ‘s’ to ‘e’..
      View my solution carefully and you will find what is wrong :)

      Like

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