Skip to content

Commit 90406c9

Browse files
[BOJ] 12871 무한 문자열 (S5)
1 parent 91eb360 commit 90406c9

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

서정우/6주차/260205.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require("fs");
2+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
3+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
4+
5+
const s = input[0].trim();
6+
const t = input[1].trim();
7+
8+
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
9+
const lcm = (a, b) => (a * b) / gcd(a, b);
10+
11+
const L = lcm(s.length, t.length);
12+
13+
const repeatToLength = (str, length) => {
14+
let result = "";
15+
while (result.length < length) result += str;
16+
return result.slice(0, length);
17+
};
18+
19+
const sString = repeatToLength(s, L);
20+
const tString = repeatToLength(t, L);
21+
22+
console.log(sString === tString ? 1 : 0);

서정우/input.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
11 12 2 24 10
2-
16 1 13 3 25
3-
6 20 5 21 17
4-
19 4 8 14 9
5-
22 15 7 23 18
6-
5 10 7 16 2
7-
4 22 8 17 13
8-
3 18 1 6 25
9-
12 19 23 14 21
10-
11 24 9 20 15
1+
abc
2+
bca

0 commit comments

Comments
 (0)