-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate2.js
More file actions
26 lines (24 loc) · 828 Bytes
/
Copy pathtemplate2.js
File metadata and controls
26 lines (24 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var readline = require('readline');
var io_interface = readline.createInterface({ input: process.stdin });
let output_numbers = [],
line_number = 0,
num_lines;
io_interface.on('line', function (line) {
if (line_number === 0) {
num_lines = parseInt(line);
} else if (line_number <= num_lines) {
let values = line.split(' ');
let value_1 = parseInt(values[0]),
value_2 = parseInt(values[1]);
let result = value_1 + value_2;
output_numbers.push(result);
}
line_number++;
});
io_interface.on('close', function () {
if (line_number < 1 + num_lines) {
// последняя строка была пустой и потому не считана
// здесь мы могли бы обработать эту ситуацию
}
process.stdout.write(output_numbers.join('\n'));
});