-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.2.py
37 lines (27 loc) · 817 Bytes
/
2.2.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
def max_color(line, color):
values = []
words = line.split()
maxm = 0
for i in range(len(words)):
if words[i] == color:
value = words[i - 1]
if int(value) > maxm:
maxm = int(value)
return maxm
def process_file(file_path):
ans = 0
counter = 0
with open(file_path, 'r') as file:
for line in file:
counter += 1
line = line.replace(':', '')
line = line.replace(';', '')
line = line.replace(',', '')
red_max = max_color(line, 'red')
green_max = max_color(line, 'green')
blue_max= max_color(line, 'blue')
ans += red_max * green_max * blue_max
return ans
file_path = input('')
ans = process_file(file_path)
print(ans)