0
0

More than 1 year has passed since last update.

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

Last updated at Posted at 2022-02-07

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

入力:18 9941 4154 8745 6456 9469 1924 1482 2010 3807 2233 7584 7675 8767 9157 5553 9282 8693 279

入力が1行なので、splitで分割して変数に代入(ここではinput)。
input[0]がNなので、これをカウンターにしてfor文で繰り返し。

カウンタiの初期値を1にして、input[0]以下にしておくことで、iをそのままinput[i]と設定できる。
(input[1]~input[N]まで表示できる)

以下回答文

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[0].split(" ");
  for(var i = 1; i <= input[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