티스토리 뷰

Algorithm/BOJ

9536 여우는 어떻게 울지?

henry1214 2019. 9. 26. 22:25

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

 

9536번: 여우는 어떻게 울지?

문제 고대 미스테리로 전해지는 여우의 울음소리를 밝혀내기 위해 한신이는 고성능 녹음기로 무장하고 숲으로 들어갔다. 하지만 숲에는 동물들이 가득해, 녹음된 음성에는 다른 동물들의 울음소리가 섞여 있다. 그러나 한신이는 철저한 준비를 해 왔기 때문에 다른 동물들이 어떤 울음소리를 내는지 정확히 알고 있다. 그러므로 그 소리를 모두 걸러내면 남은 잡음은 분명히 여우의 울음소리일 것이다. 입력 첫 번째 줄에는 테스트케이스의 개수 T가 입력된다. 각 테스트케이스는

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
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
 
int main()
{
    cin.sync_with_stdio(false);
    int t;
    cin>>t;
    cin.ignore();
    while(t--)
    {
        map<string,int> map;
        string sound;
        getline(cin,sound);
        sound+=' ';
        vector<string> word;
        int n=sound.size();
        for(int i=0,j=0;j<n;j++)
        {
            if(sound[j]==' ')
            {
                word.push_back(sound.substr(i,j-i));
                i=j+1;
            }
        }
 
        while(true)
        {
            string str;
            getline(cin,str);
            if(str=="what does the fox say?")
            {
                for(auto w : word)
                    if(map[w]==0)
                        cout<<w<<' ';
                break;
            }
            else
            {
                int n=str.size();
                for(int i=n-1;i>=0;i--)
                {
                    if(str[i]==' ')
                    {
                        map[str.substr(i+1,n-1-i)]++;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}
cs

'Algorithm > BOJ' 카테고리의 다른 글

1890 점프  (0) 2019.10.12
11048 이동하기  (0) 2019.10.12
1620 나는야 포켓몬 마스터 이다솜  (0) 2019.01.27
1707 이분 그래프  (0) 2019.01.27
2606 바이러스  (0) 2019.01.27
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday