Created
November 5, 2013 07:17
-
-
Save firstspring1845/7315135 to your computer and use it in GitHub Desktop.
逆ポーランド電卓
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stack = [] | |
for s in gets.split() | |
if ['+','-','*','/'].include?s | |
stack.push(eval(stack.pop.to_s+s+stack.pop.to_s)) | |
else | |
stack.push(s.to_i) | |
end | |
end | |
puts stack.pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment