P
P
Paritet2021-08-30 14:00:27
Node.js
Paritet, 2021-08-30 14:00:27

Readline in node js, how to accept data from multiple lines to solve test problems?

Good afternoon, don't throw stones... I'm just a beginner. Please help me get input.
As an example, you need to solve problems similar to those on the spoj.com website, but I can’t figure out the code, how can I get data from several lines and enter them into variables, can this data be entered into different variables, let’s say, into arrays? for example, the first line of two numbers and then many lines of one number, similar to this:
2 3
100
120
10
156
I could not find clear examples, please help or code example.
standard code often suggested

const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);
rl.on('line', (line) => {
// Entered string in the line variable, here you can write the solution and output it using console.log
console.log(String(result));
rl.close();
return;
}).on('close', () => process.exit(0));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question