-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path387A-GeorgeAndSleep.cpp
56 lines (55 loc) · 1009 Bytes
/
387A-GeorgeAndSleep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;
int main() {
string s,t;
cin>>s>>t;
int hh1=0,mm1=0,hh2=0,mm2=0,hour1=0,res1=0,res2=0;
for(int i=0;i<s.size();i++){
if(s[i]==':'){
hour1=hh1;
hh1=0;
continue;
}
hh1=hh1*10+s[i]-'0';
}
mm1=hh1;
hh1=hour1;
hour1=0;
// cout<<hh1<<" "<<mm1;
for(int i=0;i<t.size();i++){
if(t[i]==':'){
hour1=hh2;
hh2=0;
continue;
}
hh2=hh2*10+t[i]-'0';
}
mm2=hh2;
hh2=hour1;
// cout<<hh1<<" "<<mm1<<" "<<hh2<<" "<<mm2;
if(hh1==0 && hh2==0 && mm1>=mm2){
hh1=0;
}else if(hh1==0){
hh1=24;
}
if(mm1<mm2){
hh1-=1;
mm1+=60;
res2=mm1-mm2;
}else{
res2=mm1-mm2;
}
res1=hh1-hh2;
if(res1<0){
res1=24+res1;
}
if(res1<=9 && res2<=9)
cout<<"0"<<res1<<":"<<"0"<<res2;
else if(res1<=9)
cout<<"0"<<res1<<":"<<res2;
else if(res2<=9)
cout<<res1<<":"<<"0"<<res2;
else
cout<<res1<<":"<<res2;
return 0;
}