0
1

More than 3 years have passed since last update.

数字版のinclude? はないのか?

Posted at

メモがてらのアウトプットです。

今回想定したのはよくあるお買い物ポイントを計算するプログラムを組みました。
下記コード

qiita.rb
n = gets.to_i


d_1,p_1 = Array.new(n){gets.chomp.split(' ').map{|i| i.to_i}}.transpose
p = 0
c = 0

while n > 0 do
  if d_1[c].to_s.include?("3")
    p += (p_1[c] * 0.03).floor
  elsif d_1[c].to_s.include?("5")
    p += (p_1[c] * 0.05).floor
  else
    p += (p_1[c] * 0.01).floor
  end
  c = c + 1
  n = n - 1

end

puts p

困ったのは1点 include?の使い方です。
結果的にto_sで文字列に返して参照しましたが
数字を直接参照するメソッドはないのかな?と
思いました。

探した限り見つからなかったのですが何かあるんですかね。。。

0
1
5

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