All pastes #1753569 Raw Edit

寄せ集め

public ruby v1 · immutable
#1753569 ·published 2010-01-16 14:44 UTC
rendered paste body
require "stack.rb"print "> "while gets  input = $_  stk = Stack.new  input.split(" ").each{ |token|    case token    when "+"      stk.push(stk.pop + stk.pop)    when "-"      op_a = stk.pop      op_b = stk.pop      stk.push(op_b - op_a)    when "*"      stk.push(stk.pop * stk.pop)    when "/"      op_a = stk.pop      op_b = stk.pop      stk.push(op_b / op_a)    else      stk.push(token.to_f)    end  }  print "%f\n> " % stk.popend