Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Do you ever get tired of waiting for something to happen? The Gotta-Have-It Gadget Company thinks there is a market for a small device that can tell you how long you have been waiting. In its normal mode, it simply counts the minutes from start to stop. In the advanced mode, you can enter a start time and a stop time and it will tell you how many minutes have elapsed.
The Gotta-Have-It Gadget Company has hired you to program the advanced option. You are to write a program that will accept two times and determine how much time has transpired between them. Times will be entered in a 24-hour format. The first time will always be before the second time (but it may be larger - from 21:01 to 7:11 is 590 minutes). Your input will be the times in hours and minutes (HHMM - 21:01 would be 2101 for input). Your program should stop when the start time is 0. One minute after midnight would be represented as 1 (0 hours).
Sample Input Data:
2101
711
2359
1
1158
1159
0
Sample Output:
From 21:01 to 7:11 is 609 minutes.
From 23:59 to 0:1 is 2 minutes.
From 11:58 to 11:59 is 1 minute.
NOTE: Do not worry about the formatting of numeric output (leading/trailing spaces around numbers are acceptable). Leading zeroes are not required in times.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Source Code for a Solution to this Problem
// preprocessor directives #include <stdio.h> #define QUIT 0 int main(void) { int i,j; int time1,time2,h1,h2,m1,m2,time = 0; int res1,res2; scanf("%d %d",&time1,&time2); while(time1 != QUIT) { res1 = h1 = time1 / 100; m1 = time1 % 100; res2 = h2 = time2 / 100; m2 = time2 % 100; if(time2 < time1) h2 = h2 + 24; time2 = h2 * 60 + m2; time1 = h1 * 60 + m1; time = time2 - time1; printf("From %d:%d to %d:%d is %d minutes.\n",res1,m1,res2,m2,time); scanf("%d %d",&time1,&time2); } // while return 0; }
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
2101 711 2359 1 1158 1159 0
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
From 21:1 to 7:11 is 610 minutes. From 23:59 to 0:1 is 2 minutes. From 11:58 to 11:59 is 1 minutes.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
2101 711 2359 1 1158 1159 2359 2358 2 241 241 2 2258 2059 1430 1801 1 2 117 110 0
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
From 21:1 to 7:11 is 610 minutes. From 23:59 to 0:1 is 2 minutes. From 11:58 to 11:59 is 1 minutes. From 23:59 to 23:58 is 1439 minutes. From 0:2 to 2:41 is 159 minutes. From 2:41 to 0:2 is 1281 minutes. From 22:58 to 20:59 is 1321 minutes. From 14:30 to 18:1 is 211 minutes. From 0:1 to 0:2 is 1 minutes. From 1:17 to 1:10 is 1433 minutes.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
1816 1618 711 2101 1440 2340 1949 0119 2359 1857 801 1931 0 5
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
From 18:16 to 16:18 is 1322 minutes. From 7:11 to 21:1 is 830 minutes. From 14:40 to 23:40 is 540 minutes. From 19:49 to 1:19 is 330 minutes. From 23:59 to 18:57 is 1138 minutes. From 8:1 to 19:31 is 690 minutes.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the LSU High School Programming Contest Homepage