[Python] 알고리즘/Silver
[9536] 여우는 어떻게 울지? (Python)
-Becca-
2021. 10. 28. 17:06
[문제]
https://www.acmicpc.net/problem/9536
9536번: 여우는 어떻게 울지?
각 테스트케이스마다 여우의 울음소리를 한 줄씩, 녹음된 순서대로 출력한다. 여우의 울음소리가 녹음되어 있음이 보장된다. (알려진 것과는 달리, 여우는 모스 부호로 의사소통하지 않는다.)
www.acmicpc.net
알고리즘 분류는 문자열, 파싱 입니다.
set()을 이용하면, 섞여있는 울음소리 - 여우를 제외한 울음소리 = 여우의 울음소리를 얻을 수 있습니다.
set()은 중복된 것을 없애므로 완벽한 여우의 울음소리는 아닙니다.
[코드]
import sys
T = int(sys.stdin.readline())
for i in range(T):
sound = sys.stdin.readline().split()
animal_sound = list()
while True:
animal = sys.stdin.readline().rstrip()
if animal == "what does the fox say?":
break
else:
animal_sound.append(animal.split()[2])
fox = list(set(sound) - set(animal_sound))
for j in sound:
if j in fox:
print(j, end=" ")