알고리즘
백준 1764 : 듣보잡
Aye Bye Eye
2020. 7. 22. 11:05
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::string, int> 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의 성능은 날이 갈수록 좋아지고 있다고 한다...