1764번: 듣보잡(6분)

myeongrangcoding·2023년 12월 5일
0

백준

목록 보기
10/47

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

구현 아이디어 1분 구현 5분

풀이

듣도 보도 못한 사람 = UMapPerson[사람] == 2.

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "rt", stdin);

    int N{}, M{};

    cin >> N >> M;

    unordered_map<string, int> UMapPerson;
    vector<string> VecSortPerson;
    
    string StrPersonName;
    for (int i = 0; i < N; ++i)
    {
        cin >> StrPersonName;
        UMapPerson[StrPersonName]++;
    }
    for (int i = 0; i < M; ++i)
    {
        cin >> StrPersonName;
        UMapPerson[StrPersonName]++;
    }

    for (auto& it : UMapPerson)
    {
        if (it.second == 2)
        {
            VecSortPerson.push_back(it.first);
        }
    }

    sort(VecSortPerson.begin(), VecSortPerson.end());

    cout << VecSortPerson.size() << '\n';
    for (auto& it : VecSortPerson)
    {
        cout << it << '\n';
    }

    return 0;
}
profile
명랑코딩!

0개의 댓글