Skip to content

Commit cca546a

Browse files
[BOJ] 27111 출입 기록 (S5)
1 parent 0ff0d62 commit cca546a

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

서정우/5주차/260129.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 lines = input.slice(1);
6+
const lastMoveMap = {};
7+
let missed = 0;
8+
9+
lines.forEach((line) => {
10+
const [id, action] = line.split(" ").map(Number);
11+
const move = action === 0 ? -1 : 1;
12+
if (lastMoveMap[id]) {
13+
if (lastMoveMap[id] === move) {
14+
missed++;
15+
}
16+
lastMoveMap[id] = move;
17+
} else {
18+
if (move === -1) {
19+
missed++;
20+
}
21+
lastMoveMap[id] = move;
22+
}
23+
});
24+
25+
for (const id in lastMoveMap) {
26+
if (lastMoveMap[id] === 1) {
27+
missed++;
28+
}
29+
}
30+
31+
console.log(missed);

서정우/input.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
5 4 20
2-
1 2 3
3-
3 4 8
4-
2 3 12
5-
4 5 12
1+
8
2+
1 1
3+
2 1
4+
1 1
5+
4 1
6+
3 0
7+
5 1
8+
4 0
9+
1 0

0 commit comments

Comments
 (0)