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

Admins please answer why program always WA1?
Posted by Abdujabbor 29 Mar 2015 05:09
__author__ = 'abdujabbor'
import sys
numbers = { 0: {'o', 'q', 'z'},
            1: {'i', 'j'},
            2: {'a', 'b', 'c'},
            3: {'d', 'e', 'f'},
            4: {'g', 'h'},
            5: {'k', 'l'},
            6: {'m', 'n'},
            7: {'p', 'r', 's'},
            8: {'t', 'u', 'v'},
            9: {'w', 'x', 'y'}}


while True:
    number = input()
    if(number == '-1'):
        sys.exit(0)
    words_counter = int(input())
    words_list = []
    result = []

    for x in range(0, words_counter):
        word = input()
        words_list.append(word)

    i = 0
    t = 0
    for word in words_list:
        found = False
        finded_word = ''
        current_position = i
        for item, c in enumerate(word):
            if c in numbers[int(number[i])]:
                i += 1
                finded_word += c
            else:
                break
        if finded_word == word:
            result.append(finded_word)
        else:
            i = current_position
        t += 1
    result_words = ' '
    if len(result) > 0:
        print(result_words.join(str(item) for item in result))
    else:
        print('No solution.')