|
|
back to boardWA Python 3.6 Posted by nnchaos 27 Jan 2017 14:49 Не понимаю где ошибка. Занимаюсь в целом программированием 3 недели (как хобби) Проверял на исходном примере и на примерах, которые нашел на форуме. Ответы верны. Сюда загружаю выдаёт ошибку. 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} while True: number = input() if int(number) == -1: break num_words = int(input()) words = {} k = 500 for i in range(num_words): word = input() if len(word) < k: k = len(word) key_word = "" for a in word: key_word += str(example.get(a)) words[int(key_word)] = word answer = [] loser = "" while True: copy = number[len("".join(answer)):] x = len(copy) while x >= k: if int(copy[:x]) in words.keys(): if words[int(copy[:x])] != loser: answer.append(words[int(copy[:x])]) copy = copy[x:] x = len(copy) + 1 x -= 1 if len(answer) == 0: break elif len("".join(answer)) != len(number): loser = answer.pop() elif len("".join(answer)) == len(number): break if len(answer) == 0: print("No solution.") else: ans = " ".join(answer) print(ans) Re: WA Python 3.6 12345 5 iad i adgk g k -1 should print "i adgk" instead of "iad g k" |
|
|