File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const fs = require ( 'fs' ) ;
4+
5+ process . stdin . resume ( ) ;
6+ process . stdin . setEncoding ( 'utf-8' ) ;
7+
8+ let inputString = '' ;
9+ let currentLine = 0 ;
10+
11+ process . stdin . on ( 'data' , inputStdin => {
12+ inputString += inputStdin ;
13+ } ) ;
14+
15+ process . stdin . on ( 'end' , _ => {
16+ inputString = inputString . replace ( / \s * $ / , '' )
17+ . split ( '\n' )
18+ . map ( str => str . replace ( / \s * $ / , '' ) ) ;
19+
20+ main ( ) ;
21+ } ) ;
22+
23+ function readLine ( ) {
24+ return inputString [ currentLine ++ ] ;
25+ }
26+
27+ // Complete the towerBreakers function below.
28+ function towerBreakers ( n , m ) {
29+ return ( m == 1 || n % 2 == 0 ? 2 : 1 ) ;
30+ }
31+
32+ function main ( ) {
33+ const ws = fs . createWriteStream ( process . env . OUTPUT_PATH ) ;
34+
35+ const t = parseInt ( readLine ( ) , 10 ) ;
36+
37+ for ( let tItr = 0 ; tItr < t ; tItr ++ ) {
38+ const nm = readLine ( ) . split ( ' ' ) ;
39+
40+ const n = parseInt ( nm [ 0 ] , 10 ) ;
41+
42+ const m = parseInt ( nm [ 1 ] , 10 ) ;
43+
44+ let result = towerBreakers ( n , m ) ;
45+
46+ ws . write ( result + "\n" ) ;
47+ }
48+
49+ ws . end ( ) ;
50+ }
You can’t perform that action at this time.
0 commit comments