Time notifications

1.5

2 votes
Grammar-Verified, Basic Programming, Easy,
Problem

You are given the current time R in the HH:MM:SS format. You are also given N more time values in an array P, where every element P[i] is less than or equal to R.

Write a program to calculate the time difference between P[i] and R and print one of the following messages accordingly:

  • If the time difference is zero, print now.
  • If the time difference is in seconds but less than a minute, print X seconds ago.
  • If the time difference is in minutes but less than an hour, print X minutes ago. Ignore the seconds part of the difference.
  • If the time difference is in hours, print X hours ago. Ignore the minutes and seconds part of the difference.
  • If the value of X is 1, print the word second instead of seconds, hour instead of hours and minute instead of minutes.

Input format

  • First line: R (In the HH:MM:SS format)
  • Second line: N
  • Next N lines: P[i] (In the HH:MM:SS format, where 0i<N)

Output format

For each P[i], print the message indicating the time difference.

Constraints

0HH23
0MM59
0SS59
1N1000

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

R = 23:05:38

Now for each P[i]:

RP[0] 23:05:38 - 23:05:38 00:00:00. Time difference is zero. Hence the answer is "now".
RP[1] 23:05:38 - 23:05:02 00:00:36. Time difference is 36 seconds. Hence the answer is "36 seconds ago".
RP[2] 23:05:38 - 23:04:59 00:00:39. Time difference is 39 seconds. Hence the answer is "39 seconds ago".
RP[3] 23:05:38 - 23:04:31 00:01:07. Time difference is 1 min 7 seconds. According the rules, when time difference is in minutes but less than an hour, we ignore the seconds part of the difference. Hence the answer is "1 minute ago".
RP[4] 23:05:38 - 12:36:07 10:29:31. Time difference is 10 hours 29 mins 31 seconds. According the rules, when time difference is in hours, we ignore the minutes and seconds part of the difference. Hence the answer is "10 hours ago".
RP[5] 23:05:38 - 08:59:01 14:06:37. Time difference is 14 hours 6 mins 37 seconds. According the rules, when time difference is in hours, we ignore the minutes and seconds part of the difference. Hence the answer is "14 hours ago".
RP[6] 23:05:38 - 00:00:00 23:05:38. Time difference is 23 hours 5 mins 38 seconds. According the rules, when time difference is in hours, we ignore the minutes and seconds part of the difference. Hence the answer is "23 hours ago".

Editor Image

?