1764 : 듣보잡

서희찬·2021년 11월 12일
0

백준

목록 보기
72/105

문제

코드

import sys 
input = sys.stdin.readline


n,m = map(int,input().split()) 
cantHear=[input().strip() for i in range(n)]
cantSee =[input().strip() for i in range(m)]

#집합을 만들어주고 리스트로 형변환 
#교집합 찾는다 
cant =list(set(cantHear)& set(cantSee)) 
print(len(cant))

for cants in sorted(cant):
    print(cants)

해설

집합을 이용하면 간단하게 풀수있는 문제이다.
리스트를 입력받고 집합으로 변환후 교집합을 얻어서 리스트로 변환해주고 출력을 하면 된다.

profile
부족한 실력을 엉덩이 힘으로 채워나가는 개발자 서희찬입니다 :)

0개의 댓글