Last active
May 25, 2020 09:46
-
-
Save tonythomas01/9aa6bf46fe0eaaef1d7fb846f8b73ec2 to your computer and use it in GitHub Desktop.
Revisions
-
tonythomas01 revised this gist
May 25, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,6 @@ rl.on('line', (line) => { } // Ignore this first line now ? if (shouldProcessTestCaseLimit) { shouldProcessTestCaseLimit = false; testCaseLimit = +line; -
tonythomas01 created this gist
May 25, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // Assume you have to read something like: // 3 - number of test cases that follow // 3 - limit in this test case. // 1 2 3 - test case data // 4 // 1 2 3 4 const readline = require('readline') const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let firstLine = true; let numberOfTestCasesLine = true; let totalTestCasesCount = undefined; let testCasesProcessedCount = 0; let shouldProcessTestCaseLimit = true; let testCaseLimit; rl.on('line', (line) => { if (firstLine) { totalTestCasesCount = +line; firstLine = false; return; } // Ignore this first line now ? if (shouldProcessTestCaseLimit) { shouldProcessTestCaseLimit = false; testCaseLimit = +line; return; } console.log(`Processing test case line ${line}, with testCaseLimit: ${testCaseLimit}`); const numberArray = line.split(' ').map(Number); console.log("numberArray", numberArray); // Do your magic here. shouldProcessTestCaseLimit = true; testCasesProcessedCount++; if (totalTestCasesCount <= testCasesProcessedCount) { rl.close(); } });