Skip to content

Commit d90a2aa

Browse files
[BOJ] 1871 좋은 자동차 번호판 (B2)
1 parent 5d9eb8a commit d90a2aa

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

서정우/10주차/260306.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 lines = input.slice(1).map((line) => line.split("-"));
12+
13+
lines.forEach((line) => {
14+
const [a, b] = line;
15+
const aValue = a
16+
.split("")
17+
.reduce(
18+
(sum, char, idx, arr) =>
19+
sum + Math.pow(26, arr.length - idx - 1) * (char.charCodeAt(0) - 65),
20+
0,
21+
);
22+
const bValue = Number(b);
23+
console.log(Math.abs(aValue - bValue) <= 100 ? "nice" : "not nice");
24+
});

서정우/input.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
선데이코딩
2-
딩코이데선
1+
2
2+
ABC-0123
3+
AAA-9999

0 commit comments

Comments
 (0)