ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1002. Phone Numbers

WA 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
Posted by jaibaiku 9 Mar 2017 02:35
12345
5
iad
i
adgk
g
k
-1

should print "i adgk" instead of "iad g k"