MHGOC02 - Editorial

Question

Tick Tock Clock

Difficulty level

Easy

Prerequisites

None

Code:

int main ()

{

int dataset;

scanf ("%d", &dataset);

while ( dataset-- ) {

int time1_h;

int time1_m;

int time1_s;

scanf ("%d:%d:%d", &time1_h, &time1_m, &time1_s);

int time2_h;

int time2_m;

int time2_s;

scanf ("%d:%d:%d", &time2_h, &time2_m, &time2_s);

int time1_in_seconds = (time1_h * 3600) +

(time1_m * 60) + time1_s;

int time2_in_seconds = (time2_h * 3600) +

(time2_m * 60) + time2_s;

int seconds_diff;

if ( time1_in_seconds > time2_in_seconds )

seconds_diff = (24 * 3600) - (time1_in_seconds

  • time2_in_seconds);

else

seconds_diff = time2_in_seconds-time1_in_seconds;

printf ("%d HOURS ", seconds_diff / 3600 );

printf ("d MINUTES ", (seconds_diff 3600) / 60);

printf ("d SECONDS\n", (seconds_diff 3600) % 60);

}

return 0;

}