252일차 - BOJ no.1764

https://www.acmicpc.net/problem/1764

My Solution

from collections import defaultdict
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())
hear, see = [], []
for _ in range(N):
    hear.append(sys.stdin.readline().rstrip())
for _ in range(M):
    see.append(sys.stdin.readline().rstrip())

dic = defaultdict(int)
for i in hear:
    dic[i] += 1

for j in see:
    dic[j] += 1


result = []
for i in dic:
    if dic[i] == 2:
        result.append(i)
result.sort()
for i in result:
    print(i)

좋은 웹페이지 즐겨찾기