Skip to content

Commit 84d966e

Browse files
committed
105차 2번 문제풀이
1 parent d06759c commit 84d966e

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
.toString()
9+
.trim()
10+
.split("\n");
11+
12+
function solution(input) {
13+
const n = +input[0];
14+
const check = Array.from({ length: 26 }, () => Array(26).fill(false));
15+
16+
for (let i = 1; i <= n; i++) {
17+
const [a, , b] = input[i].split(" ");
18+
const x = a.charCodeAt(0) - 97;
19+
const y = b.charCodeAt(0) - 97;
20+
check[y][x] = true; // ✅ 방향 반대로!
21+
}
22+
23+
for (let k = 0; k < 26; k++) {
24+
for (let i = 0; i < 26; i++) {
25+
for (let j = 0; j < 26; j++) {
26+
if (check[i][k] && check[k][j]) {
27+
check[i][j] = true;
28+
}
29+
}
30+
}
31+
}
32+
33+
const m = +input[n + 1];
34+
const result = [];
35+
36+
for (let i = n + 2; i < n + 2 + m; i++) {
37+
const [a, , b] = input[i].split(" ");
38+
const x = a.charCodeAt(0) - 97;
39+
const y = b.charCodeAt(0) - 97;
40+
41+
if (x === y) {
42+
result.push("F");
43+
} else {
44+
result.push(check[y][x] ? "T" : "F");
45+
}
46+
}
47+
48+
return result.join("\n");
49+
}
50+
51+
console.log(solution(input));

0 commit comments

Comments
 (0)