LoginSignup
0
0

More than 3 years have passed since last update.

複数の値を標準入力から受け取る方法

Last updated at Posted at 2021-04-19

はじめに

paizaのスキルチェックは、一度に複数の値が入力される問題だった。
一度に複数の値を受け取る方法が分からなかったので備忘録として残しています。

結論

splitメソッドを利用する事で複数の値を受け取ることができます。

apple orange grape

例えば、上記の3つが標準入力される値とした場合、下記のように記述する事で

fruits = gets.split(' ')
p fruits

まとめて値を受け取ることができます。
※受け取った値は配列となっているので、数値を使用する場合は文字列から数値に変換する必要があります。

["apple", "orange", "grape"]
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