반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

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

2. Vector STL :: http://www.crocus.co.kr/500 / http://www.crocus.co.kr/501


맵과 벡터를 혼용하여 써보기 좋은 문제인 것 같다.


아직 필자는 멀티맵 이라는 개념을 잘 몰라서 하나의 key에 여러 value를 어떻게 넣는지는 잘 모르지만,


필자가 아는 범위 내에서는 map에 vector를 쓰면 되는 것 같다.


년도를 key로, 노래 제목을 Value로 잡고 벡터를 이용하면 쉽게 해결할 수 있다.






소스 코드 : 


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
60
61
62
63
64
65
66
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
 
using namespace std;
 
map<int, vector<string>> m;
 
int main()
{
    m[1967].push_back("DavidBowie");
    m[1969].push_back("SpaceOddity");
    m[1970].push_back("TheManWhoSoldTheWorld");
    m[1971].push_back("HunkyDory");
    m[1972].push_back("TheRiseAndFallOfZiggyStardustAndTheSpidersFromMars");
    m[1973].push_back("AladdinSane");
    m[1973].push_back("PinUps");
    m[1974].push_back("DiamondDogs");
    m[1975].push_back("YoungAmericans");
    m[1976].push_back("StationToStation");
    m[1977].push_back("Low");
    m[1977].push_back("Heroes");
    m[1979].push_back("Lodger");
    m[1980].push_back("ScaryMonstersAndSuperCreeps");
    m[1983].push_back("LetsDance");
    m[1984].push_back("Tonight");
    m[1987].push_back("NeverLetMeDown");
    m[1993].push_back("BlackTieWhiteNoise");
    m[1995].push_back("1.Outside");
    m[1997].push_back("Earthling");
    m[1999].push_back("Hours");
    m[2002].push_back("Heathen");
    m[2003].push_back("Reality");
    m[2013].push_back("TheNextDay");
    m[2016].push_back("BlackStar");
 
 
    int n;
    scanf("%d"&n);
 
    while (n--)
    {
        int s, e;
        scanf("%d %d"&s, &e);
 
        int cnt = 0;
        for (int i = s; i <= e; i++)
            if (!m[i].empty())
                for (int j = 0; j < m[i].size(); j++)
                    cnt++;
 
        cout << cnt << endl;
 
        for (int i = s; i <= e; i++)
            if (!m[i].empty())
                for (int j = 0; j < m[i].size(); j++)
                    cout << i << " " << m[i][j] << endl;
    }
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

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

[2563번] 색종이  (0) 2017.04.21
[5347번] LCM  (0) 2017.04.21
[13410번] 거꾸로 구구단  (0) 2017.04.21
[1914번] 하노이 탑  (0) 2017.04.21
[6588번] 골드바흐의 추측  (2) 2017.04.21