結果

問題 No.1135 RPN
ユーザー kokatsu
提出日時 2022-03-15 22:42:10
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 434 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 207,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 14:36:15
合計ジャッジ時間 3,178 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto A = readln.chomp.split;

    int idx = -1;
    auto B = new int[](N);
    foreach (a; A) {
        if (a == "+") {
            B[idx-1] += B[idx];
            B[idx--] = 0;
        }
        else if (a == "-") {
            B[idx-1] -= B[idx];
            B[idx--] = 0;
        }
        else {
            B[++idx] = a.to!int;
        }
    }

    B[0].writeln;
}
0