結果

問題 No.1135 RPN
ユーザー 👑 obakyan
提出日時 2020-08-04 13:28:30
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 443 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 14:20:13
合計ジャッジ時間 1,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n", "*l")
local s = io.read()
local stack = {}
for w in s:gmatch("%g+") do
  if w == "+" then
    local v1 = stack[#stack - 1]
    local v2 = stack[#stack]
    stack[#stack - 1] = v1 + v2
    table.remove(stack)
  elseif w == "-" then
    local v1 = stack[#stack - 1]
    local v2 = stack[#stack]
    stack[#stack - 1] = v1 - v2
    table.remove(stack)
  else
    table.insert(stack, tonumber(w))
  end
end
print(stack[1])
0