BOJ::문제풀이

1764 듣보잡

2영재 2018. 2. 24. 16:03

1764 듣보잡


1. 듣도 못한 사람을 map<string, int> m 에 넣는다.


2. 보도 못한 사람이면서 듣도 못한 사람을 string 벡터 v에 넣는다.


3. 정렬한 후 출력한다.


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
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);
    map<stringint> m;
    vector<string> v;
 
    int a, b;
    cin >> a >> b;
 
    while (a--) {
        string str;
        cin >> str;
        m.emplace(str, 1);
    }
 
    while (b--) {
        string str;
        cin >> str;
        if (m.count(str)) {
            v.push_back(str);
        }
    }
 
    sort(v.begin(), v.end());
    cout << v.size() << "\n";
    for (auto ss : v) {
        cout << ss << "\n";
    }
 
}
cs