7-3 時間換算 (15 分)
本題要求編寫程式,以hh:mm:ss的格式輸出某給定時間再過n秒後的時間值(超過23:59:59就從0點開始計時)。
輸入格式:
輸入在第一行中以hh:mm:ss的格式給出起始時間,第二行給出整秒數n(<60)。
輸出格式:
輸出在一行中給出hh:mm:ss格式的結果時間。
輸入樣例:
11:59:40
30
輸出樣例:
12:00:10
#include<stdio.h>
int main()
{
int h,m,s;
int n;
scanf("%d:%d:%d",&h,&m,&s);
scanf("%d",&n);
s+=n;
if(s>=60)
{
if(m==59)
{
h+=1;
m=0;
s-=60;
}
else
{
m+=1;
s-=60;
}
}
if(h>=24)
h-=24;
printf("%02d:%02d:%02d\n",h,m,s);
}