KKanging

[백준] 28432번 끝말잇기 (python) 본문

기타/백준

[백준] 28432번 끝말잇기 (python)

천방지축 개발자 2023. 8. 7. 01:49
from sys import stdin
from collections import deque



input = stdin.readline


N = int(input())

str_li = []
s1 , s2 = '@','@'

for i in range(N):
    temp = input()[:-1] #문자열 
    if temp == "?":
        if str_li:
            s1 = str_li[-1][-1]
        else:
            pass
    if str_li:
        if str_li[-1] == '?':
            s2 = temp[0]

    str_li.append(temp)

M = int(input())


for i in range(M):
    temp = input()[:-1]
    if (temp[0] == s1 or s1=='@') and (temp[-1] == s2 or s2=='@'):
        if temp not in str_li:
            print(temp)
            break

 

'기타 > 백준' 카테고리의 다른 글

[백준]28438 행렬연산(행렬 계산하기) python  (0) 2023.08.07