阅读背景:

迭代哈希以检索与数组匹配的值

来源:互联网 

I have the code -

我有代码 -

class Conversion
  hash ={'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000}
  puts "enter the string"
  input = gets.chomp.upcase.split(//)
  result = 0
  hash.each do | key, value |
  case key
    when 'M'
        result = result + value
    when 'D'
        result = result + value
    when 'C'
        result = result + value
    when 'L'
        result = result + value
    when 'X'
        result = result + value
    when 'V'
        result = result + value
    when 'I'
        result = result + value
    end
  end
  puts result
  end
  c= Conversion.new
class Conversion



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: