728x90
320x100
1269번: 대칭 차집합
첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어
www.acmicpc.net
반응형
📌 접근 방법
- 겹치는 부분을 카운팅해서 A에서도 빼주고 B 에서도 빼주는 식으로 계산 !
✅ Pass Code
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iterator>
#include<map>
#include<set>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int total=n+m;
map<int,bool> M;
for(int i=0; i<n; i++){
int x;
cin>>x;
M[x]=true;
}
int cnt=0;
for(int i=0; i<m; i++){
int x;
cin>>x;
if(M[x]==true){
cnt++;
}
}
cout<<total-2*cnt<<"\n";
return 0;
}
![](https://t1.daumcdn.net/keditor/emoticon/face/large/013.png)
728x90
반응형
'Coding Test > Baekjoon' 카테고리의 다른 글
[BOJ/백준/C++] 11478번 서로 다른 부분 문자열의 개수 (0) | 2024.01.27 |
---|---|
[BOJ/백준/C++] 18870번 좌표 압축 (0) | 2024.01.27 |
[BOJ/백준/C++] 1181번 단어 정렬 (0) | 2024.01.27 |
[BOJ/백준/C++] 1436번 영화감독 숌 (1) | 2024.01.26 |
[BOJ/백준/C++] 2231번 분해합 (1) | 2024.01.26 |