2
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.

半角スペースで区切られた2つの正の整数を足し算して出力する

Posted at

paizaDランク問題で、標準入力に半角スペースで入力して計算する方法が分からなかったのでメモ

ruby.rb
s = gets.split(' ').map(&:to_i) #splitで半角空けて配列を作り、map(&:to_i)で数値に変更
result = s[0] + s[1] #配列内の数値を足す
puts result

これまで改行で区切られた問題しか解いていなかったので、標準入力で半角空けて2つ入力する方法を分かってなかった。
基礎固め大事。

2
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
2
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?