We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 85935ec commit d4284b1Copy full SHA for d4284b1
1 file changed
live11/test113/문제2/조진우.js
@@ -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