[URI Online Judge] – 1019 – Time Conversion

Read an integer value, which is the duration in seconds of a given event in a factory and tell print it in the format expressed in hours:minutes:seconds.

Input

The input file contains an integer N.

Output

Print the read time in the input file (seconds) converted in hours:minutes:seconds like the following example.

Sample Input Sample Output
556 0:9:16
1 0:0:1
140153 38:55:53

Solution:

#include <cstdio>
int main(){
 int t, h = 0, m = 0, s = 0;
 scanf("%d", &t);
 if (t >= 60 * 60){
 h = t / (60 * 60);
 t %= (60 * 60);
 }
 if (t >= 60){
 m = t / 60;
 t %= 60;
 }
 s = t;
 printf("%d:%d:%d\n", h, m, s);
 return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s