我在这一行有这个错误(if change_needed - coins[i] >= 0 then
)
字符串不能被强制转换为 Fixnum
从我的代码中,我不明白为什么它现在不起作用。任何有关如何最好地解决此问题的帮助将不胜感激。
user_input = gets
change_needed = 0
coins = []
coins_part, change_needed_part = user_input.split(':')
coins = coins_part.split(',')
change_needed = change_needed_part.to_i
i = 0
coins_used = []
while change_needed != 0 do
if change_needed - coins[i] >= 0 then
change_needed = change_needed - coins[i]
coins_used << coins[i]
else
i += 1
end
end