-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.cpp
More file actions
42 lines (32 loc) · 706 Bytes
/
time.cpp
File metadata and controls
42 lines (32 loc) · 706 Bytes
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
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
// uncomment the following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
int H0, M0, H1, M1;
cin >> H0 >> M0;
cin >> H1 >> M1;
// insert your code here
int H=0, M=0;
if (M1 >= M0) {
M = M1 - M0;
} else {
M = 60 - (M0 - M1);
H1 --;
}
if (H0 <= 23 && H0 != 0) {
H = H1 + (24-H0);
} else {
H = H1 - H0;
}
if (H < 0) {
H += 24;
} else if (H >= 24) {
H -= 24;
}
cout << H << " " << M << endl; // print the result
return 0;
}