forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagedecoding.py
50 lines (40 loc) · 952 Bytes
/
imagedecoding.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
import fileinput
first = True
images = []
for line in fileinput.input():
# If not part of an image
if line[0] not in ['#', '.']:
# Add a new image
images.append([])
# If part of an image
to_print = line[0]
line = line[2:]
# Add to image
images[-1].append("")
for i in line.split():
i = int(i)
for j in range(i):
images[-1][-1] = images[-1][-1] + to_print
if to_print == '#':
to_print = '.'
else:
to_print = '#'
first = True
for i in images[:-1]:
# Print lines between images
if first:
first = False
else:
print()
# Strip newlines
i = i[1:]
# Print image
for j in i:
print(j)
# Check if image is valid
works = True
for j in range(0, len(i)-1):
if len(i[j]) != len(i[j+1]):
works = False
if not works:
print("Error decoding image")