0%

[題解]時間差計算

a096/ 時間差計算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0)
using namespace std;

signed main(){
int a1,b1,c1,a2,b2,c2;
scanf("%d:%d:%d",&a1,&b1,&c1);
scanf("%d:%d:%d",&a2,&b2,&c2);
int a = a1*3600+b1*60+c1,b = a2*3600+b2*60+c2;

if(b-a>=0){
int temp = b-a;
printf("%02d:%02d:%02d",temp/3600,(temp%3600)/60,temp%60);
}
else{
int temp = 86400+b-a;
printf("%02d:%02d:%02d",temp/3600,(temp%3600)/60,temp%60);
}
}