프로그래밍/Python
백준_python 1269번 대칭 차집합
O'bin
2024. 6. 5. 23:37
<문제 링크>
https://www.acmicpc.net/problem/1269
<정답 코드>
sol 1) 대칭 차집합 연산자 사용
1
2
3
4
5
6
|
a, b = map(int, input().split())
set_a = set(map(int, input().split()))
set_b = set(map(int, input().split()))
print(len(set_a ^ set_b))
|
cs |
파이썬에서 제공하는 대칭 차집합 연산자 : ^
sol 2) 교집합 연산자 사용
1
2
3
4
5
6
7
8
|
a, b = map(int, input().split())
set_a = set(map(int, input().split()))
set_b = set(map(int, input().split()))
both = len(set_a & set_b)
print(a + b - (both * 2))
|
cs |
교집합 연산자 & 로 교집합 구한 후,
집합 a의 길이 + 집합 b의 길이 - (교집합 길이 * 2)
https://docs.python.org/3/tutorial/datastructures.html#sets
5. Data Structures
This chapter describes some things you’ve learned about already in more detail, and adds some new things as well. More on Lists: The list data type has some more methods. Here are all of the method...
docs.python.org