题解 | #牛牛的时钟#
https://www.nowcoder.com/practice/36fd5f6b6236452f99f0ea59cd3447e0
#include <stdio.h> typedef struct Time{ int hour,min,sec; //时分秒 int hour_left,min_left,sec_left; //考虑到会有进位的情况,记录每次t秒转换成的时分秒,方便转换 }Time; int main(){ Time _TIME; int n,time; _TIME.hour = 0; _TIME.min = 0; _TIME.sec = 0; scanf("%d",&n); for (int i = 0;i < n;i++){ scanf("%d",&time); //将秒钟转换成时分秒 _TIME.sec_left = time % 60; time -= _TIME.sec_left; _TIME.min_left = (time / 60) % 60; time -= _TIME.min_left * 60; _TIME.hour_left = (time / 3600) % 24; //将转换出的时分秒加上去,并进行进位换算 _TIME.sec += _TIME.sec_left; _TIME.min += _TIME.sec / 60; _TIME.sec %= 60; _TIME.min += _TIME.min_left; _TIME.hour += _TIME.min / 60; _TIME.min %= 60; _TIME.hour += _TIME.hour_left; _TIME.hour %= 24; printf("%d %d %d\n",_TIME.hour,_TIME.min,_TIME.sec); } }