Sunday, April 30, 2017

URI Solution 1103 - Alarm Clock - Solution in C++ | Ad Hoc

URI Solution  1103 - Alarm Clock - Solution in C++ | Ad Hoc


Main link on URI - https://www.urionlinejudge.com.br/judge/en/problems/view/1103

URI Online Judge Solution  | Ad Hoc


Problem Name: URI Problem - Alarm Clock
Problem Number : URI - 1103
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1103 Code in CPP:


#include <iostream>
using namespace std;

int main()
{
 int ho_i, ho_f, mi_i, mi_f;
 int ho_r, mi_r;
 bool ver_h = false, ver_m = false, ver_1 = false, ver_2 = false;
 
 while(cin >> ho_i >> mi_i >> ho_f >> mi_f)
 {
  if(ho_i == 0 && ho_f == 0 && mi_i == 0 && mi_f == 0)
   return 0;
  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  if(ho_i > ho_f)
   ver_h = true;

  if(mi_i > mi_f)
   ver_m = true;

  if(ho_i < ho_f && mi_i > mi_f)
   ver_1 = true;

  if(ho_i == ho_f && mi_i != mi_f && mi_i > mi_f)
   ver_2 = true;

  ho_i *= 60;
  ho_f *= 60;

  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  if(ver_h == true){
   ho_r = (1440 - ho_i) + ho_f;
  }else{
   ho_r = ho_f - ho_i; 
  }

  if(ver_m == true){
   mi_r = (60 - mi_i) + mi_f;
  }else{
   mi_r = mi_f - mi_i; 
  }

  if(ver_1 == true)
   ho_r -= 60;

  if(ver_h == true && ver_m == true)
   ho_r -= 60;

  if(ver_2 == true)
   ho_r += 1380;

  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  cout << (ho_r + mi_r) << endl;
  ver_h = false;
  ver_m = false;
  ver_1 = false;
  ver_2 = false;
 }
 
 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.