我正在努力让这种方法有效,它给了我错误:16:在block (2 levels) in roman_to_integer': undefined method
indlude?'
我不明白为什么。请帮忙。
我只是在学习,但我不明白为什么它不认为罗马是一个字符串。
def roman_to_integer roman
result = 0
singles = {"M"=> 1000, "D"=> 500, "C"=> 100,"L"=> 50, "X"=> 10, "V"=> 5, "I"=> 1}
double = {"CM"=> 900,"CD"=> 400,"XC"=> 90,"XL"=> 40,"XL"=> 40,"IX"=> 9, "IV"=> 4,}
roman= roman.upcase
something = roman.split("")
something.each do |key|
unless singles.include?(key)
puts "not valid roman numeral"
end
double.each do |key, value|
if roman.indlude?(key)
result += value
roman.slice!(key)
end
end
while roman.length > 0
single.each do |key, value|
if single.include?(key)
result += value
roman.slice!(key)
end
end
end
end
result
end
答案 0 :(得分:1)
您的意思是include
,而不是indlude
。请记住,这是一台机器,拼写错误的概念是一个非常棘手的解释。