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.

ABC086A Product AtCoderの問題をRubyで解説

Posted at

正解の解答例

a,b = gets.split.map(&:to_i)

if a * b % 2 == 0
  puts "Even"
else
  puts "Odd"
end

1行目では入力、入力値を配列に入れる、配列の入力値を数値オブジェクトに変換する処理を行なっています。
他の解答例でsplit(" ")と解答している方もいらっしゃいますが、splitの記述だけでスペースは区別できるようです。

if文ではaとbの積を2で割ることで余りが出るか判別しています。
2で割り切れればEvenを出力します。
そうでなければ奇数なのでOddを出力します。

■参考サイト
https://leokun0210.hatenablog.com/entry/2019/08/25/162033

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?