[백준 1269번 C/C++] 대칭 차집합

 

https://www.acmicpc.net/problem/1269

 

1269번: 대칭 차집합

첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어

www.acmicpc.net


 

해결전략

 

map

 


 

코드

 

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int a, b, sum = 0;
    cin >> a >> b;

    map<int, bool> m;

    for (int i = 0; i < a + b; i++) {
        int tmp;
	    cin >> tmp;

	if (m[tmp] == true)
		m.erase(tmp);
	else
		m[tmp] = true;
	}

    cout << m.size();
}