0
1

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 3 years have passed since last update.

標準入力で連続した数値を受け取る方法(paiza用)

Posted at

#Rubyで文字列ではなく連続した数値を入力したい
paizaの問題を解くときに標準入力で数値を受け取りたいが、paizaの入力方法ではgets.to_iだけでは不十分だったのでメモとして残します。

#NG例
入力は以下である場合
1 2 3

example.rb
number = gets.chomp.split.map(&.to_i)
puts number

map(&.to_i)のように'&'の後に'.'をつける方法がネットによく出ているが、paizaの環境ではsyntaxエラーがでて動かない。

#成功例

example.rb
number = gets.chomp.split.map(&:to_i)
puts number

'.'を':'に変えると動いた。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?