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 1542. Autocompletion

WA#2 don't know what's the problem. HELP!
Posted by ZHENG WANG 27 Dec 2018 08:43
Can someone help me? Please?
I do it with Python3 ,and does not print out empty line after last queue
here's my code:

def getSecond(temp):
                return temp[1]

if __name__ == '__main__':
    while True:
        try:

            N = int(input())
            Words = []
            for n in range(N):
                Words.append(input().split())
                Words[n][1] = int(Words[n][1])

            M = int(input())
            Beginners = []
            for m in range(M):
                Beginners.append(input())

            for mm in range(M):
                start = list(Beginners[mm])
                matchs = []
                for nn in range(N):
                    word = list(Words[nn][0])
                    flag = True
                    for s in range(len(start)):
                        if start[s] != word[s]:
                            flag = False
                            break
                    if(flag):
                        matchs.append(Words[nn])
                if matchs != []:
                    matchs.sort()
                    matchs.sort(key = getSecond, reverse = True)
                    count = 0
                    for match in matchs:
                        if count > 10:
                            break
                        print(match[0])
                        count += 1

                if mm != M-1:
                    print()


        except:
            break


Re: WA#2 don't know what's the problem. HELP!
Posted by zksumon 5 Dec 2019 08:20
if no word found with any query dont print any new line