Notice
Recent Posts
Recent Comments
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Today
Total
Archives
관리 메뉴

cyphen156

백준-집합과 맵 1269 대칭 차집합 본문

컴퓨터공학/알고리듬 풀이

백준-집합과 맵 1269 대칭 차집합

cyphen156 2025. 6. 2. 11:39

대칭 차집합

대칭 차집합이란 (A - B) + (B - A)를 대칭 차집합이라고 한다.

대칭 차집합의 원소 개수를 출력하는 프로그램을 만들어라

한마디로 (A+B) - (A ∩ B)이다.

제약사항

  • 0 < Elements <= 200,000
  • 0 < Data <= 100,000,000

주의 사항

없다.

CPP풀이

대칭 차집합_1269.cpp

/**
 * 백준 대칭 차집합_1269
 * 대칭 차집합이란 (A - B) + (B - A)를 대칭 차집합이라고 한다.
 * 대칭 차집합의 원소 개수를 출력하는 프로그램을 만들어라
 * 한마디로 (A+B) - (A ∩ B)이다.
 * 
 * 제한사항
 *****************************************
 * 0 < Elements <= 200,000               *
 * 0 < Data <= 100,000,000               *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 20분
 */


#include <iostream>
#include <set>

using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A, B;

    cin >> A >> B;

    set<int> setA, setB;
    for (int i = 0; i < A; ++i)
    {
        int data;
        cin >> data;
        setA.insert(data);
    }
    
    for (int i = 0; i < B; ++i)
    {
        int data;
        cin >> data;
        setB.insert(data);
    }

    int count = 0;

    for (auto& data : setA)
    {
        if (setB.find(data) != setB.end())
        {
            count++;
        }
    }
    cout << setA.size() + setB.size() - 2 * count;
    return 0;
}

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리에 있습니다.

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com