문제
1269번: 대칭 차집합
첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어
www.acmicpc.net
코드
My answer
import sys
input=sys.stdin.readline
an,bn=map(int,input().split())
a=set(map(int,input().split()))
b=set(map(int,input().split()))
k=a&b
print(an+bn-len(k)*2)
Another answer
input()
print(len(set(input().split())^set(input().split())))
풀이
나는 교집합의 수를 구한다음 a의원소갯수+b의원소갯수-교집합*2를 해줬는데 파이썬에는 ^라는 대칭차집합 연산자가 존재했다.. 그냥 저 연산자 쓰면된다.
728x90