8000 Merge pull request #416 from Joshua-Shin/master · REDICALED/basic-algo-lecture@a8e1e86 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8e1e86

Browse files
Merge pull request encrypted-def#416 from Joshua-Shin/master
Update 14725.cpp
2 parents 24a5540 + 6cc5279 commit a8e1e86

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

0x1F/solutions/14725.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : Joshua-Shin
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/05e6530bfdb74e16bcedecd7da39b0f9
44
#include <bits/stdc++.h>
55
using namespace std;
66

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() {
829
ios::sync_with_stdio(0);
930
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+
*/

0 commit comments

Comments
 (0)
0