A Second Opinion

Question

Solution

Idea

To break this problem into several small problems:

  1. Find the hours

  2. Find the minutes

  3. Find the seconds

For hours, we just need to use integer division /, hours = input secs / 3600. After we get the hours, substract it from our input secs.

Do the similar operation on minutes. The remaining are seconds.

Code

https://github.com/mendax1234/Coding-Problems/blob/main/kattis/secondopinion/secondopinion.c
#include <stdio.h>

int main()
{
  long secs;
  scanf("%ld", &secs);
  // Get hours
  long hours = secs / 3600;
  secs -= 3600 * hours;
  // Get mins
  long mins = secs / 60;
  secs -= 60 * mins;
  printf("%ld : %ld : %ld\n", hours, mins, secs);
}

Last updated