[Ruby] Ruby score calculation program

less than 1 minute read

I wrote a simple score calculation program, so my memorandum

First, the code below

qiita.rb


k,n = gets.chomp.split(" ").map{|i| i.to_i}
a = []
d = []

k.times do
  d_1,a_1 = gets.chomp.split('').map{|i| i.to_i}
  d.push(d_1)
  a.push(a_1)
end

num = 0
check = []


while k> 0
  if d[num].between?(1,9)
    check.push(((a[num].fdiv(n) * 100) * 0.8).floor)
  elsif d[num] >= 10
    check.push(0)
  else
    check.push((a[num].fdiv(n) * 100).floor)
  end


  if check[num] >= 80
    puts "A"
  elsif check[num] >= 70
    puts "B"
  elsif check[num] >= 60
    puts "C"
  else
    puts "D"
  end
  num = num + 1
  k = k-1
end

The first if statement checks whether points can be deducted from the deadline for submission. If there is no deadline assuming the submission deadline (d_1), there is no origin 20% penalty if 1 to 9 days late I have set 0 points for 10 days or more.

The second if statement returns the final score in four levels.

The new method used this time is fdiv. In short, it is almost the same as to_f.

x/y.to_f To become x.fdiv(y) Just fixing

Tags:

Updated: