반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. map STL

2. 접미사 배열 이해


접미사 배열이 무엇인지 이해하면 map STL을 통해 간단히 해결할 수 있는 문제이다.


주석에 달린 내용이 전부인 문제이고, 어떻게 접근하냐에 따라 달라지는 문제이지만 


map STL을 쓰면 더욱더 간단히 해결되는 문제이다.



소스 코드 : 


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
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
 
using namespace std;
 
map<string, int> m;
 
int main()
{
    char tmp[1002];
    string str;
 
    scanf("%s", tmp);
 
    str = tmp;
 
    int len = str.size();
 
    // 접미사를 모두 가지게 되는 map을 형성
    for (int i = 0; i < len; i++)
        m[str.substr(i, len)] = 1;
    
    // map은 자동적으로 오름차순 정렬을 해주기에 그대로 출력하면 된다.
    for (auto it = m.begin(); it != m.end(); it++)
        printf("%s\n", it->first.c_str());
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

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

[4354번] 문자열 제곱  (1) 2017.02.23
[1305번] 광고  (0) 2017.02.22
[1764번] 듣보잡  (0) 2017.02.20
[1068번] 트리  (0) 2017.02.20
[2015번] 수들의 합 4  (0) 2017.02.20