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

 

1764번: 듣보잡

첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다. ��

www.acmicpc.net

 

해싱 해싱 해싱을할까요

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
#include <algorithm>
 
int N, M;
std::unordered_map<std::stringint> unknownList;
 
std::vector<std::string> ans;
 
void input()
{
    std::cin >> N >> M;
    std::string input;
    for (int i = 0; i < N; ++i)
    {
        std::cin >> input;
        unknownList[input] += 1;
    }
    for (int i = 0; i < M; ++i)
    {
        std::cin >> input;
        unknownList[input] += 2;
        if (unknownList[input] == 3)
        {
            ans.push_back(input);
        }
    }
}
 
int main()
{
    std::cin.tie(0);
    std::cin.sync_with_stdio(false);
    std::cout.tie(0);
    std::cout.sync_with_stdio(false);
    input();
    std::cout << ans.size() << '\n';
    std::sort(ans.begin(), ans.end());
    for (auto& it : ans)
    {
        std::cout << it << '\n';
    }
    return 0;
}
cs

C++ unordered map의 성능은 날이 갈수록 좋아지고 있다고 한다...

'알고리즘' 카테고리의 다른 글

백준 1722 : 순열의 순서  (0) 2020.07.30
백준 8979 : 올림픽  (0) 2020.07.23
백준 9517 : 아이 러브 크로아티아  (0) 2020.07.21
백준 14890 : 경사로  (0) 2020.07.17
백준 1094 : 막대기  (0) 2020.07.16

+ Recent posts