-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1408.cpp
More file actions
68 lines (56 loc) · 1.35 KB
/
1408.cpp
File metadata and controls
68 lines (56 loc) · 1.35 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
// 1408. 24
// 2021.06.13
// 수학
#include<iostream>
#include<string>
using namespace std;
struct Time
{
int hour;
int minute;
int second;
Time(int hour_, int minute_, int second_) : hour(hour_), minute(minute_), second(second_) {}
Time() = default;
};
int main()
{
string currentTime, startTime;
cin >> currentTime >> startTime;
Time current(stoi(currentTime.substr(0, 2)), stoi(currentTime.substr(3, 2)), stoi(currentTime.substr(6, 2)));
Time start(stoi(startTime.substr(0, 2)), stoi(startTime.substr(3, 2)), stoi(startTime.substr(6, 2)));
Time ans;
ans.second = start.second - current.second;
if (ans.second < 0)
{
ans.second += 60;
start.minute--;
}
ans.minute = start.minute - current.minute;
if (ans.minute < 0)
{
ans.minute += 60;
start.hour--;
}
ans.hour = start.hour - current.hour;
if (ans.hour < 0)
{
ans.hour += 24;
}
string hour = to_string(ans.hour);
if (hour.size() == 1)
{
hour = '0' + hour;
}
string minute = to_string(ans.minute);
if (minute.size() == 1)
{
minute = '0' + minute;
}
string second = to_string(ans.second);
if (second.size() == 1)
{
second = '0' + second;
}
cout << hour << ":" << minute << ":" << second << endl;
return 0;
}