题解 | #时间差#
时间差
https://ac.nowcoder.com/acm/problem/20691
#include <math.h>
void fun1(int n)//把秒转换成时分秒
{
int i,j;
int h=0,m=0,s=0;
for(i=0;i<n;i++)
{
s++;
if(s==60)
{
s=0;
m++;
}
if(m==60)
{
m=0;
h++;
}
}
if(h/10<=0)
printf("0%d:",h);
else
printf("%d:",h);
if(m/10<=0)
printf("0%d:",m);
else
printf("%d:",m);
if(s/10<=0)
printf("0%d",s);
else
printf("%d",s);
}
int fun2(int a,int b,int c)//把时分秒转换成秒
{
return a*3600+b*60+c;
}
int main()
{
int h1,h2,m1,m2,s1,s2,sum=0;
scanf("%d:%d:%d",&h1,&m1,&s1);
scanf("%d:%d:%d",&h2,&m2,&s2);
sum+= abs(fun2(h1,m1,s1)-fun2(h2,m2,s2));
fun1(sum);
}