paizaの懸賞問題解答(期限切れ)(正答かは知らない)
paizaの懸賞問題の提出が間に合わず、提出し損ねたのでここに保存する。
しりとりをして最後に残った人数と人の番号を出力する問題。python3で解答。
ppl,wordNum,remarkNum=map(int,input().split()) wordList=[] for _ in range(wordNum): word=input() if word[-1]!='z': wordList.append(word) humanList=[i for i in range(1,ppl+1)] #「newGameかつwordが前回の語尾と異なる始まり」、もしくは語尾がz、もしくはwordListに含まれていないときは脱落 newGame=True nowIndex=0 for _ in range(1,remarkNum+1): word=input() if (not newGame and lastWord[-1]!=word[0])\ or word[-1]=='z' or (word not in wordList): humanList.pop(nowIndex) newGame=True nowIndex=nowIndex % len(humanList) else: wordList.remove(word) lastWord=word newGame=False nowIndex=(nowIndex+1) % len(humanList) #print(humanList) print(len(humanList)) for i in range(len(humanList)): print(humanList[i])