기타/백준
[백준] 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