Skip to content

Commit 315b573

Browse files
[BOJ] 14626 ISBN (B1)
1 parent 9b14c17 commit 315b573

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

서정우/8주차/260220.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("fs");
2+
const filePath =
3+
process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
4+
const input = fs
5+
.readFileSync(filePath)
6+
.toString()
7+
.trim()
8+
.split("\n")
9+
.map((el) => el.trim());
10+
11+
const number = input[0];
12+
const numbers = number
13+
.slice(0, -1)
14+
.split("")
15+
.map((el) => (Number.isNaN(Number(el)) ? el : Number(el)));
16+
const checkNumber = Number(number.at(-1));
17+
const starIndex = numbers.findIndex((el) => el === "*");
18+
19+
const sum = numbers.reduce(
20+
(acc, cur, idx) =>
21+
Number.isInteger(cur) ? acc + cur * (idx % 2 === 0 ? 1 : 3) : acc,
22+
0,
23+
);
24+
25+
for (let i = 0; i < 10; i++) {
26+
if ((sum + i * (starIndex % 2 === 0 ? 1 : 3) + checkNumber) % 10 === 0) {
27+
console.log(i);
28+
break;
29+
}
30+
}

서정우/input.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
5
2-
300 400 500 400 300
1+
9788968322*73

0 commit comments

Comments
 (0)