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 3 years have passed since last update.

Ruby 得点計算プログラム

Posted at

簡易得点計算のプログラムを書いたので自分用備忘録

まずは下記コード

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

1つめのif文は提出期限に対する点数の減点の可否をチェックしてます。
提出期限(d_1)を想定して期限ないであれば原点なし
1~9日遅れたら二割減点
10日以上は0点にしてます。

2つめのif文で最終的な点数に対する評価を4段階で返しています。

今回新しく使ったメソッドは fdiv です。
一言で言うとto_fとほぼ同じです。

x / y.to_f
ってなるのを
x.fdiv(y)
って直しているだけ

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?