-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1061(3).py
executable file
·79 lines (65 loc) · 1.92 KB
/
_1061(3).py
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
69
70
71
72
73
74
75
76
77
78
79
# #1061 Event time by Neilor Tonin.
# Function to verify if the first date is less than the seccond.
from typing import Sequence
def isLater(start, end):
if start['hour'] > end['hour']:
return False
elif start['hour'] == end['hour']:
if start['min'] > end['min']:
return False
elif start['min'] == end['min']:
if start['sec'] > end['sec']:
return False
elif start['sec'] == end['sec']:
return 0
# If reach this end is because the end hour is after the start.
return True
# Receiving and generating start day.
start = {}
hourtemp = (input().split())
start['day'] = int(hourtemp[1])
hourtemp = (input().split())
start['hour'] = int(hourtemp[0])
start['min'] = int(hourtemp[2])
start['sec'] = int(hourtemp[4])
# print(start)
# Receiving and gererating the end day.
end = {}
hourtemp = (input().split())
end['day'] = int(hourtemp[1])
hourtemp = (input().split())
end['hour'] = int(hourtemp[0])
end['min'] = int(hourtemp[2])
end['sec'] = int(hourtemp[4])
# print(end)
# Calculating the duration.
duration = {}
# Day
duration['day'] = end['day'] - start['day']
later = False
if isLater(start, end) == False:
# print('The start hour is later than the end,')
later = True
duration['day'] -= 1
# Hour
if (later == True):
duration['hour'] = 24 - start['hour'] + end['hour']
else:
duration['hour'] = end['hour'] - start['hour']
# Min
if start['min'] > end['min']:
duration['min'] = 60 - end['min'] + start['min']
duration['hour'] -= 1
else:
duration['min'] = end['min'] - start['min']
# Sec
if start['sec'] > end['sec']:
duration['sec'] = 60 - end['sec'] + start['sec']
duration['min'] -= 1
else:
duration['sec'] = end['sec'] - start['sec']
# Showing output.
print(f"{duration['day']} dia(s)")
print(f"{duration['hour']} hora(s)")
print(f"{duration['min']} minuto(s)")
print(f"{duration['sec']} segundo(s)")