0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

2 行目で与えられる N 個の整数の入力 JavaScript編

Posted at

2 行目で与えられる N 個の整数の入力 JavaScript編

入力:5
   8 1 3 10 100

lines[0]が繰り返し回数、lines[1]に数値が半角スペースで入っている。

lines[1] を split で分割して適当な変数(配列)に代入し、それを lines[0] 回、for文で繰り返し処理してあげればいい。

以下解答例


process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ!!
var lines = [];
var reader = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
reader.on('line', (line) => {
lines.push(line);
});
reader.on('close', () => {

input = lines[1].split(" ");
for(var i = 0; i < lines[0]; i++){
console.log(input[i]);
}

});


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?