Given n time durations in the form of MM : SS, where MM denotes minutes and SS denotes the seconds. The task is to add all the time duration and output answer in the form of HH : MM : SS.
Input : n = 5 duration1 = 0 : 45 duration1 = 2 : 31 duration1 = 3 : 11 duration1 = 2 : 27 duration1 = 1 : 28 Output : 0 : 10 : 22 Initially, sum = 0 On adding duration 1, sum = 0 hour 0 minutes 45 seconds. On adding duration 2, sum = 0 hour 3 minutes 16 seconds. On adding duration 3, sum = 0 hour 6 minutes 27 seconds. On adding duration 4, sum = 0 hour 8 minutes 54 seconds. On adding duration 5, sum = 0 hour 10 minutes 22 seconds
The idea is to convert all the given time duration to seconds. Once we know the duration in seconds, we can calculate the sum of durations in seconds.
In order to get the number of hours, we have to divide the total duration in seconds by 3600. The remainder is used to calculate the number of minutes and seconds. By dividing the remainder with 60 we get the number of minutes, and the remainder of that division is the number of seconds.
Below is the implementation of this approach:
0 : 10: 22
- Time difference between expected time and given time
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Program to find the time after K minutes from given time
- Convert given time into words
- Calculate speed, distance and time
- Java | Current date and time
- Print system time in C++ (3 different ways)
- Convert timestamp to readable date/time in PHP
- Time Functions in Python | Set-2 (Date Manipulations)
- C++ Program to print current Day, Date and Time
- C program to print digital clock with current time
- Find time when hour and minute hands superimpose
- Minimum time required to complete a work by N persons together
- Minimum time required to fill a cistern using N pipes
- Program to check if tank will overflow, underflow or filled in given time
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.