fork download
  1. #include <cstdio>
  2. using namespace std;
  3.  
  4. class time
  5. {
  6. public:
  7. int minutes;
  8. time(int h, int min) : minutes(0)
  9. {
  10. minutes += h * 60 * 11; //to remove non int numbers such as 12/11 I multiply them by 11 and I'am storing everything in minutes
  11. minutes += min * 11;
  12. }
  13.  
  14. time(time a, time b)
  15. {
  16. minutes = b.minutes - a.minutes;
  17. }
  18.  
  19. bool operator >= (time obj)
  20. {
  21. if (this->minutes >= obj.minutes) return true;
  22. return false;
  23. }
  24.  
  25. void add(int a)
  26. {
  27. minutes += a;
  28. }
  29.  
  30. void showTime() //
  31. {
  32. int hours = minutes/60/11;
  33. int minits = (minutes - hours*60*11) / 11;
  34. printf("%i:%i\n", hours,minits);
  35. }
  36.  
  37. };
  38.  
  39. int solve(time t1, time t2) //t2 is the end time
  40. {
  41. time zero(0, 0);
  42. const int interval = 12 * 60; //not 12/11 becouse I multiply everything by 11
  43. while (t1 >= zero) zero.add(interval);
  44. int passCount = 0;
  45. while (t2 >= zero)
  46. {
  47. passCount++;
  48. zero.add(interval);
  49. }
  50. return passCount;
  51. }
  52.  
  53. void abc() // this function is just to see if everything is working. Passing times are rounded
  54. {
  55. time zero(0, 0);
  56. time end(24,00);
  57. const int interval = 12 * 60;
  58. do
  59. {
  60. zero.showTime();
  61. zero.add(interval);
  62. }while(end >= zero);
  63. }
  64.  
  65. int main()
  66. {
  67. //abc();
  68. unsigned long long n;
  69. scanf("%llu", &n);
  70. while (n--)
  71. {
  72. int a, b;
  73. scanf("%i:%i", &a, &b);
  74. time time1(a, b);
  75. scanf("%i:%i", &a, &b);
  76. time time2(a, b);
  77. printf("%i", solve(time1, time2));
  78. if(n>0) printf(("\n"));
  79. }
  80. return 0;
  81. }
  82.  
Success #stdin #stdout 0s 3464KB
stdin
2

02:09
02:10

02:09
02:10
stdout
7
0