Skip to content

Commit d4284b1

Browse files
committed
113차 2번 문제풀이
1 parent 85935ec commit d4284b1

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const input = require("fs")
2+
.readFileSync(
3+
process.platform === "linux"
4+
? "/dev/stdin"
5+
: require("path").join(__dirname, "input.txt"),
6+
"utf8"
7+
)
8+
.trim()
9+
.split("\n");
10+
11+
function solution(input) {
12+
const N = Number(input[0]);
13+
const root = {};
14+
15+
for (let i = 1; i <= N; i++) {
16+
const arr = input[i].split(" ");
17+
const path = arr.slice(1);
18+
19+
let current = root;
20+
for (let food of path) {
21+
if (!current[food]) {
22+
current[food] = {};
23+
}
24+
current = current[food];
25+
}
26+
}
27+
28+
function dfs(node, depth) {
29+
const keys = Object.keys(node).sort();
30+
for (let key of keys) {
31+
console.log("--".repeat(depth) + key);
32+
dfs(node[key], depth + 1);
33+
}
34+
}
35+
36+
dfs(root, 0);
37+
}
38+
39+
solution(input);

0 commit comments

Comments
 (0)