cmod.ify
[1764] 듣보잡 본문
728x90
반응형
출력 형식을 사전순으로 정렬하는 거 까먹음
문제를 잘 읽자
집합은 & 연산자로 교집합을 구할 수 있다
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
noListen = set()
noSaw = set()
for i in range(n):
name = input()
noListen.add(name)
for j in range(m):
name = input()
noSaw.add(name)
cnt = 0
result = noListen & noSaw
realResult = []
for word in result:
cnt+=1
realResult.append(word.split('\n')[0])
print(cnt)
realResult.sort()
for word in realResult:
print(word)728x90
반응형
'BASIC > 코딩테스트' 카테고리의 다른 글
| [1003] 피보나치 함수 (0) | 2025.12.19 |
|---|---|
| [11047] 동전0 (0) | 2025.12.19 |
| [11723] 집합 (0) | 2025.12.18 |
| [1620] 나는야 포켓몬 마스터 이다솜 (0) | 2025.12.18 |
| [코드트리] 체크 다이아몬드 (2) | 2023.10.24 |