URI-1047-no-solution in c++

URI Online Judge Solution | 1047||Game Time with Minutes

Problem No:1047
Problem Level:Beginner
Online Judge:URI
Problem Link:https://www.urionlinejudge.com.br/judge/en/problems/view/1047 
URI 1047 No Problem
  


 Solution in C++:
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,d,hours,minutes;
  std::cin >> a>>b>>c>>d;
  hours=c-a;
  if(hours<0){
    hours=24+(c-a);
  }
  minutes=d-b;
  if (minutes<0) {
    minutes=60+(d-b);
    hours--;
  }
  if (a==c && b==d) {
    std::cout << "O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)" << '\n';
  }else{
    std::cout << "O JOGO DUROU "<<hours<<" HORA(S) E "<<minutes<<" MINUTO(S)" << '\n';
  }
  return 0;
}



 Explanation:

Here,at first we declared four integer denoting a=Start Hour
                                                                           b=Start Minute
                                                                           c=End Hour
                                                                           d=End Minute
                                                                           hours=Total hour spent
                                                                           minutes=Total minutes spent
Then we subtracted the Start Hour from End Hour.If the result comes negative,we have to add that result with 24 to get  the total hours(As it was given that it hours can be maximum of 24 hours).Then we subtracted the Start Minute from The End Minute.If the result comes negative,we have to add the result with 60 to get the total minutes.And we have to subtract One hour from the total hour if the minutes becomes negative.

And finally we got the total time needed.















 


No comments

Powered by Blogger.