Skip to content

Commit ab57dd8

Browse files
Merge pull request #720 from jinoo0306/main
[조진우] 113차 라이브 코테 제출
2 parents b1abdeb + d4284b1 commit ab57dd8

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
let index = 0;
13+
const T = Number(input[index++]);
14+
const output = [];
15+
16+
for (let t = 0; t < T; t++) {
17+
const N = Number(input[index++]);
18+
const numbers = [];
19+
20+
for (let i = 0; i < N; i++) {
21+
numbers.push(input[index++]);
22+
}
23+
24+
numbers.sort();
25+
26+
let consistent = true;
27+
for (let i = 0; i < N - 1; i++) {
28+
if (numbers[i + 1].startsWith(numbers[i])) {
29+
consistent = false;
30+
break;
31+
}
32+
}
33+
34+
output.push(consistent ? "YES" : "NO");
35+
}
36+
37+
return output.join("\n");
38+
}
39+
40+
console.log(solution(input));
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)