输入样例:
123 4577973
输出样例:
12:42:59
核心思想:
该程序的主要任务是将输入的时间差(以秒为单位)转换为标准的时分秒格式。为了确保精度,程序还实现了四舍五入的功能。
完整源码:
#include
#include
int main()
{int start_time, end_time;scanf("%d %d", &start_time, &end_time);int time_diff = end_time - start_time;
if(time_diff % 100 >= 50){time_diff = ceil(time_diff / 100.0) * 100;}else{time_diff = floor(time_diff / 100.0) * 100;}
int hours = time_diff / 3600;
int minutes = (time_diff % 3600) / 60;
int seconds = time_diff % 60;
printf("%02d:%02d:%02d\n", hours, minutes, seconds);
return 0;
}
测试效果: