Home (Python)[백준][그리디] 듣보잡
Post
Cancel

(Python)[백준][그리디] 듣보잡

1764번: 듣보잡

문제 풀이


set() 함수를 이용하여 집합 연산(&)을 이용하면 간단하게 풀 수 있다.

소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
n, m = map(int, input().split())

no_hear = set()
no_see = set()
for i in range(n):
    no_hear.add(input())

for i in range(m):
    no_see.add(input())

answer = sorted(list(no_hear & no_see))

print(len(answer))
for i in answer:
    print(i)
This post is licensed under CC BY 4.0 by the author.