문제
풀이
- split함수를 사용하여 울음 소리의 입력을 sounds 배열로 변환함.
- 질문이 주어지기 전까지 동물 별 울음 소리를 animals 배열에 넣어줌.
- 질문이 주어지면, for문을 돌며 sounds에서 animals에 존재여부를 확인 후, 존재 시 값을 없앰.
- sounds에서 for문을 돌며 존재하는 값만 출력함.
코드
import sys
def solution() :
t = int(sys.stdin.readline())
for _ in range(t) :
sounds = sys.stdin.readline().rstrip().split()
animals = []
while 1 :
s = sys.stdin.readline().rstrip().split()
if s[-1] == 'say?' :
for i in range(len(sounds)) :
if sounds[i] in animals :
sounds[i] = ''
for s in sounds :
if s != '' :
print(s, end = ' ')
break
else :
animals.append(s[-1])
solution()