习题9-1 时间换算 (15分)
代码:
#include <stdio.h>
int main()
{
char time[9];
int i = 0, hh = 0, mm = 0, ss = 0, n = 0;
gets(time);
scanf("%d", &n);
for (i = 0; i < 2; i++) hh = hh * 10 + (time[i] - '0');
for (i = 3; i < 5; i++) mm = mm * 10 + (time[i] - '0');
for (i = 6; i < 8; i++) ss = ss * 10 + (time[i] - '0');
if (n + ss >= 60) {
ss = n + ss - 60;
if (mm + 1 >= 60) {
mm = 1 + mm - 60;
if (hh + 1 >= 24) hh = hh + 1 - 24;
else hh += 1;
}
else mm += 1;
}
else ss += n;
printf("%02d:%02d:%02d", hh, mm, ss);
return 0;
}