This program is a clock that only displays minutes passed since midnight. This program is supposed to be really simple but because of some "aesthetic bug", I wrote quite a lot if-else statements that I think can be simplified.
Format Input
The first line will contain an integer
T
, the number of test cases. Each test case will contain an numberN
, the number displayed by the strange clock.Format Output
For each test case, print “Case X: “ (X starts with 1) and then print what time it is in 24 hours HH:MM format.
Constraints
1 <=
T
<= 10000 <=
N
<= 1439
#include <stdio.h>
int main()
{
int T;
scanf("%d", &T);
for (int i = 1; i <= T; i++) {
int N;
scanf("%d", &N);
int hours = N / 60;
int minutes = N % 60;
printf("Case #%d: ", i);
if (N < 10) {
printf("00:0%d\n", N);
} else if (N > 10 && N < 60) {
printf("00:%d\n", N);
} else if (N > 60 && N < 600) {
if (minutes == 0) {
printf("0%d:00\n", hours);
} else if (minutes > 0 && minutes < 10) {
printf("0%d:0%d\n", hours, minutes);
} else {
printf("0%d:%d\n", hours, minutes);
}
} else {
if (minutes == 0) {
printf("%d:00\n", hours);
} else if (minutes > 0 && minutes < 10) {
printf("%d:0%d\n", hours, minutes);
} else {
printf("%d:%d\n", hours, minutes);
}
}
}
}