반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. map STL


첫번째 input을 모두 받아준 후 map에 넣어준다.

이때 map에는 여우의 울음소리를 순서대로 출력해야하니 index를 key로 두고 저장한다.


그다음에는 각 동물의 울음소리를 no라는 map에 받아준다.


마지막으로 map을 돌며 no에 해당하면 넘어가고 그 외에는 모두 출력해준다.


이때 주의해야할 점은 여우 울음소리 마지막에  ' '(space)를 넣어주어야 한다.


즉, 만약 wa wa wa 였다면  'wa wa wa'가 아닌 'wa wa wa '가 정답이다.






소스 코드 : 


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
54
55
56
57
58
59
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
 
using namespace std;
 
map<int, string > mp;
map<string, int> no;
int main()
{
    int tc;
    scanf("%d"&tc);
    while (tc--)
    {
        int idx = 1;
        mp.clear();
        no.clear();
 
        while (1)
        {
            string tmp;
            cin >> tmp;
 
            char t = getchar();
            if (t == '\n')
            {
                mp[idx++= tmp;
                break;
            }
            mp[idx++= tmp;
        }
 
        while (1)
        {
            string tmp, go, say;
            cin >> tmp >> go >> say;
            if (tmp == "what")
                break;
 
            no[say] = 1;
        }
 
        for (auto it = mp.begin(); it != mp.end(); it++)
        {
            if (no[it->second] == 1)
                continue;
            cout << it->second << " ";
        }
        cout << endl;
 
        string buffer;
        getline(cin, buffer);
    }
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

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

[10840번] 구간 성분  (0) 2018.02.07
[2257번] 화학식량  (2) 2018.02.06
[11332번] 시간초과  (0) 2018.02.05
[5670번] 휴대폰 자판  (0) 2018.01.26
[13458번] 시험 감독  (2) 2018.01.26