I wrote a simple score calculation program, so a memorandum for myself

First of all, the following code

`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 submission deadline. There is no origin if there is no deadline assuming the submission deadline (d_1) 20% deduction if delayed by 1-9 days I give 0 points for 10 days or more.

The second if statement returns the evaluation of the final score in four stages.

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

x / y.to_f To be x.fdiv(y) I'm just fixing it

Recommended Posts