문제 링크입니다: https://www.acmicpc.net/problem/1269
1269번: 대칭 차집합
첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어
www.acmicpc.net
set 자료구조를 적절히 사용하면 쉽게 풀 수 있는 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <set> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N, M; | |
cin >> N >> M; | |
vector<int> A(N), B(M); | |
set<int> ASet, BSet; | |
for (int i = 0; i < N; i++) | |
{ | |
cin >> A[i]; | |
ASet.insert(A[i]); | |
} | |
for (int i = 0; i < M; i++) | |
{ | |
cin >> B[i]; | |
BSet.insert(B[i]); | |
} | |
int result = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
result += BSet.find(A[i]) == BSet.end(); | |
} | |
for (int i = 0; i < M; i++) | |
{ | |
result += ASet.find(B[i]) == ASet.end(); | |
} | |
cout << result << "\n"; | |
return 0; | |
} |

개발환경:Visual Studio 2022
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2670번 연속부분최대곱 (0) | 2024.05.05 |
---|---|
백준 14267번 파닭파닭 (3) | 2024.05.03 |
백준 7795번 먹을 것인가 먹힐 것인가 (0) | 2024.04.24 |
백준 12094번 2048 (Hard) (1) | 2024.04.21 |
백준 2776번 암기왕 (0) | 2024.04.20 |