-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva850.py
50 lines (41 loc) · 1.02 KB
/
uva850.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 sys
n = int(input())
input()
phrase = 'the quick brown fox jumps over the lazy dog'
def match(line):
if len(line) != len(phrase):
return False
for i, c in enumerate(line):
if (c in mapping and mapping[c] != phrase[i]) or (c not in mapping and phrase[i] in mapped):
return False
if c not in mapping:
mapping[c] = phrase[i]
mapped.add(phrase[i])
return True
for i in range(n):
lines = []
while True:
try:
line = input()
except:
break
if (line):
lines.append(line)
else:
break
found_match = False
for line in lines:
mapping = {' ': ' '}
mapped = set()
found_match = match(line)
if found_match:
break
if found_match:
for line in lines:
for c in line:
print(mapping[c], end='')
print('')
else:
print('No solution.')
if i != n-1:
print('')