<문제 링크>
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
'프로그래밍 > Python' 카테고리의 다른 글
백준_python 2805번 나무 자르기 (이분 탐색, 시간초과) (0) | 2024.06.11 |
---|---|
백준_python 4358번 생태학 (소수 반올림) (1) | 2024.06.10 |
파이썬_zip() 함수 (0) | 2024.06.04 |
백준_python 1931번 회의실 배정 (리스트 정렬) (0) | 2024.05.31 |
백준_python 11726번 2×n 타일링(DP) (0) | 2024.05.27 |