File tree Expand file tree Collapse file tree 1 file changed +42
-5
lines changed Expand file tree Collapse file tree 1 file changed +42
-5
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : Joshua-Shin
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/05e6530bfdb74e16bcedecd7da39b0f9
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
- int main (void ){
7
+ const int MX = 1000 * 15 + 5 ;
8
+ map<string, int > nxt[MX];
9
+ int root = 1 ;
10
+ int unused = 2 ;
11
+ void insert (vector<string> &v) {
12
+ int cur = root;
13
+ for (auto s : v) {
14
+ if (!nxt[cur][s])
15
+ nxt[cur][s] = unused++;
16
+ cur = nxt[cur][s];
17
+ }
18
+ }
19
+ void dfs (int cur, int d) {
20
+ for (auto nx : nxt[cur]) {
21
+ string level;
22
+ for (int i = 0 ; i < d; i++)
23
+ level += " --" ;
24
+ cout << level << nx.first << ' \n ' ;
25
+ dfs (nx.second , d + 1 );
26
+ }
27
+ }
28
+ int main () {
8
29
ios::sync_with_stdio (0 );
9
30
cin.tie (0 );
10
-
11
- }
31
+ int n;
32
+ cin >> n;
33
+ for (int i = 0 ; i < n; i++) {
34
+ int m;
35
+ cin >> m;
36
+ vector<string> inputStr (m);
37
+ for (int i = 0 ; i < m; i++)
38
+ cin >> inputStr[i];
39
+ insert (inputStr);
40
+ }
41
+ dfs (1 , 0 );
42
+ }
43
+
44
+ /*
45
+ 일반 트리이 문제처럼 한글자 단위로 저장하는것이 아니라 문자열을 통째로 저장한다.
46
+ 또한 사전 편찬순으로 출력해야 하기에 nxt[MX]을 Map 자료구조로 선언한다.
47
+ nxt[cur][s] = 현재 정점번호가 cur이고, 자식노드 중 문자열이 s인 노드의 정점 번호.
48
+ */
You can’t perform that action at this time.
0 commit comments