File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments