sm 기술 블로그

95. 1269(대칭 차집합) 본문

문제/백준_파이썬

95. 1269(대칭 차집합)

sm_hope 2022. 6. 21. 09:11
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

A = set(map(int, input().split()))
B = set(map(int, input().split()))
C = 0
C += len(list(A-B))
C += len(list(B-A))

print(C)

문제요약

A와B의 차집합, B와A의 차집합 개수를 구해라.

 

해설

집합에서 차집합,교집합,합집합에 관한 것을 문제로 다룬 것이다.

집합자료형은 아래를 참고하자.

https://smhope.tistory.com/257

 

집합자료형

집합이 다음과 같이 주어졌다고 해보자. >>> s1 = set([1, 2, 3, 4, 5, 6]) >>> s2 = set([4, 5, 6, 7, 8, 9]) 차집합 >>> s1.difference(s2) {1, 2, 3} >>> s2.difference(s1) {8, 9, 7} >>> s1 - s2 {1, 2, 3} >..

smhope.tistory.com

 

Comments