#include <stdio.h> struct time { int hour; int minute; int second; }; void going(struct time *h,int *t,int n); int main() { int n=0; scanf("%d",&n); struct time h[n]; //给结构体数组h[0]初始化 h[0].hour=0; h[0].minute=0; h[0].second=0; int t[n];//定义一个数组存放输入的时间 int i=0; for(i=0;i<n;i++)//输入时间 { scanf("%d",&t[i]); } going(h,t,n);//调用函数计算经过t秒后的时间 for(i=0;i<n;i++)//输出计算后的时间 { printf("%d %d %d\n",h[i].hour,h[i].minute,h[i].second); } return 0; } void going(struct time *h,int *t,int n)//定义函数计算经过t秒后的时间 { int i=0; int temp;//定义临时变量temp接收t时间 for(i=0;i<n;i++) { temp=t[i]; while(temp>=60)//判断temp是否大于60秒 { //temp大于60秒进入while循环 if((h[i].minute+1)<60) { h[i].minute=h[i].minute+1; } else { h[i].minute=0; if((h[i].hour+1)<24) { h[i].hour=h[i].hour+1; } else { h[i].hour=0; } } temp=temp-60; } //经过while循环后temp已经小于60 if((h[i].second+temp)<60)//再进行时间加法运算 { h[i].second=h[i].second+temp; } else { h[i].second=(h[i].second+temp)%60; if((h[i].minute+1)<60) { h[i].minute++; } else { h[i].minute=0; if((h[i].hour+1)<24) { h[i].hour++; } else { h[i].hour=0; } } } if(i<n-1)//给结构体数组的下一元素赋值为本次循环计算后的时间 h[i+1]=h[i]; } }