WA#7 please help!
Послано
micrus 9 дек 2017 21:49
example = {'i': 1, 'j': 1, 'a': 2, 'b': 2, 'c': 2,
'd': 3, 'e': 3, 'f': 3, 'g': 4, 'h': 4,
'k': 5, 'l': 5, 'm': 6, 'n': 6, 'p': 7,
'r': 7, 's': 7, 't': 8, 'u': 8, 'v': 8,
'w': 9, 'x': 9, 'y': 9, 'o': 0, 'q': 0, 'z': 0}
def create_words(number, amount):
words = {}
for i in range(int(amount)):
word = str(input())
key = ""
key = "".join([str(example.get(j)) for j in word])
if key in str(number):
words[key] = word
return words
def create_answers(number, words):
answers = {}
for i in words.keys():
if i != number[:len(i)]:
continue
answer = [words[i]]
answer_key = i
copy = number[len("".join(answer)):]
x = len(copy)
while x > 0:
if copy[:x] in words.keys():
answer.append(words[copy[:x]])
answer_key += copy[:x]
copy = copy[x:]
x = len(copy) + 1
x -= 1
if len(answer) == 0:
continue
elif len(answer) in answers.keys():
continue
elif answer_key == n:
answers[len(answer)] = answer
else:
continue
return answers
while True:
n = input()
if int(n) == -1:
break
a = input()
i = create_answers(n, create_words(n, a))
if len(i) == 0:
print("No solution.")
else:
y = min(i.keys())
print(" ".join(i[y]))
Edited by author 09.12.2017 22:06