Skip to content

Commit 3791cbf

Browse files
committed
[Silver IV] Title: 대칭 차집합, Time: 596 ms, Memory: 39512 KB -BaekjoonHub
1 parent 9ff65d6 commit 3791cbf

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Silver IV] 대칭 차집합 - 1269
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1269)
4+
5+
### 성능 요약
6+
7+
메모리: 39512 KB, 시간: 596 ms
8+
9+
### 분류
10+
11+
자료 구조, 해시를 사용한 집합과 맵, 트리를 사용한 집합과 맵
12+
13+
### 제출 일자
14+
15+
2025년 1월 14일 09:21:12
16+
17+
### 문제 설명
18+
19+
<p>자연수를 원소로 갖는 공집합이 아닌 두 집합 A와 B가 있다. 이때, 두 집합의 대칭 차집합의 원소의 개수를 출력하는 프로그램을 작성하시오. 두 집합 A와 B가 있을 때, (A-B)와 (B-A)의 합집합을 A와 B의 대칭 차집합이라고 한다.</p>
20+
<p> 예를 들어, A = { 1, 2, 4 } 이고, B = { 2, 3, 4, 5, 6 } 라고 할 때, A-B = { 1 } 이고, B-A = { 3, 5, 6 } 이므로, 대칭 차집합의 원소의 개수는 1 + 3 = 4개이다.</p>
21+
22+
### 입력
23+
24+
<p>첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어진다. 각 집합의 원소의 개수는 200,000을 넘지 않으며, 모든 원소의 값은 100,000,000을 넘지 않는다.</p>
25+
26+
### 출력
27+
28+
<p>첫째 줄에 대칭 차집합의 원소의 개수를 출력한다.</p>
29+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
#include <set>
3+
4+
using namespace std;
5+
6+
int main() {
7+
int A, B;
8+
cin >> A >> B;
9+
10+
set<int> Aset, Bset, Aans, Bans;
11+
12+
for (int i = 0; i < A; i++) {
13+
int value;
14+
cin >> value;
15+
Aset.insert(value);
16+
Aans.insert(value);
17+
}
18+
19+
for (int i = 0; i < B; i++) {
20+
int value;
21+
cin >> value;
22+
Bset.insert(value);
23+
Bans.insert(value);
24+
}
25+
26+
int ans = 0;
27+
for (auto i : Bset) {
28+
Aans.erase(i);
29+
}
30+
for (auto i : Aset) {
31+
Bans.erase(i);
32+
}
33+
34+
cout << Aans.size() + Bans.size() << '\n';
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)