반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. Map STL :: http://www.crocus.co.kr/604


맵을 어떻게 이용하는 지 알려주는 가장 기본적인 문제이다.


맵을 모른다면 이 문제를 풀기위해 다양한 코딩을 해야할 것이지만, 맵을 이해하고 이용한다면


손쉽게 해결할 수 있는 문제이다.



소스 코드 : 


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
47
48
49
50
51
52
53
#include <map>
#include <vector>
#include <iostream>
#include <cstdio>
 
using namespace std;
 
map<string, int> MAP;
vector<string> vc;
 
int main()
{
    int n, m, cnt = 0;
    char str[22];
 
    scanf("%d %d"&n, &m);
 
    // 듣을 맵에 저장
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
        MAP[str]++;
    }
 
    // 보를 맵에 저장
    for (int i = 0; i < m; i++)
    {
        scanf("%s", str);
        MAP[str]++;
    }
 
    // 듣보를 탐색
    for (auto it = MAP.begin(); it != MAP.end(); it++)
    {
        if (it->second == 2)
        {
            cnt++;
            vc.push_back(it->first);
        }
    }
 
    // 듣보 수 출력
    printf("%d\n", cnt);
 
    // 듣보 이름을 출력
    for(auto it = vc.begin(); it != vc.end(); it++)
        printf("%s\n", it->c_str());
    
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[1305번] 광고  (0) 2017.02.22
[11656번] 접미사 배열  (0) 2017.02.22
[1068번] 트리  (0) 2017.02.20
[2015번] 수들의 합 4  (0) 2017.02.20
[3078번] 좋은 친구  (1) 2017.02.16