时间换算 c语言
发布网友
发布时间:2022-04-21 14:14
我来回答
共4个回答
热心网友
时间:2023-07-20 02:59
#include<stdio.h>
int main()
{
int hh,mm,ss;
int add;
scanf("%d:%d:%d",&hh,&mm,&ss);
scanf("%d",&add);
ss=ss+add;
if(ss>=60){
ss=ss-60;
mm++;
if(mm>=60){
mm=mm-60;
hh++;
if(hh>=24){
hh=hh-24;
}
}
}
printf("%d:%d:%d\n",hh,mm,ss);
}
追问测试结果一分(满分15)
追答你把测试截图发来看看
热心网友
时间:2023-07-20 03:00
网上一位大神写的,感觉是目前见过写的最好的方法。
#include<stdio.h>
int main()
{
int hh, mm, ss;
scanf("%d:%d:%d",&hh,&mm,&ss);
int n;
scanf("%d",&n);
ss = ss + n;
mm += (ss - ss%60) > 0, ss %= 60;
hh += (mm - mm%60) > 0, mm %= 60;
hh %= 24;
printf("%02d:%02d:%02d",hh,mm,ss);
return 0;
}
热心网友
时间:2023-07-20 03:00
#include <stdio.h>
int main()
{
int hours, minutes, seconds;
int num;
scanf("%d:%d:%d", &hours, &minutes, &seconds);
scanf("%d", &num);
int quotient,remain;
quotient = (seconds + num) / 60;
seconds = (seconds + num) % 60;
remain = (quotient + minutes) / 60;
minutes = (quotient + minutes) % 60;
hours = (remain + hours) % 24;
printf("%d:%d:%d", hours, minutes, seconds);
return 0;
}
热心网友
时间:2023-07-20 03:01
int main(int argc, char *argv[])
{
int t,m,s,n;
scanf("%d:%d:%d",&t,&m,&s);
scanf("%d",&n);
int all;
all=t*60*60+m*60+s+n;
printf("\n%d:%d:%d",all/3600,(all%3600)/60,(all%3600)%60);
return 0;
}