문제풀이/자료구조

[Python/파이썬] 백준 1269번 대칭 차집합

딜레이레이 2024. 5. 8. 22:25

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

 

코드

a_num, b_num = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))
print(len(a-b)+len(b-a))

 

파이썬은 집합 자료형과 관련 연산이 정의되어 있어서 이 문제를 쉽게 풀 수 있었다. a와 b를 set()을 이용하여 집합으로 만들고, '-' 연산을 이용하여 A-B와 B-A 차집합을 구한 뒤 두 차집합의 길이를 더해주면 된다