結果

問題 No.1135 RPN
ユーザー bluemeganebluemegane
提出日時 2020-09-08 14:17:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 63,164 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2023-08-19 20:09:24
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
20,776 KB
testcase_01 AC 58 ms
20,636 KB
testcase_02 AC 65 ms
18,708 KB
testcase_03 AC 65 ms
20,748 KB
testcase_04 AC 65 ms
18,676 KB
testcase_05 AC 65 ms
22,748 KB
testcase_06 AC 65 ms
20,696 KB
testcase_07 AC 57 ms
20,644 KB
testcase_08 AC 58 ms
20,656 KB
testcase_09 AC 66 ms
20,640 KB
testcase_10 AC 66 ms
20,744 KB
testcase_11 AC 65 ms
20,812 KB
testcase_12 AC 65 ms
20,812 KB
testcase_13 AC 65 ms
22,724 KB
testcase_14 AC 65 ms
20,764 KB
testcase_15 AC 57 ms
20,624 KB
testcase_16 AC 57 ms
20,784 KB
testcase_17 AC 57 ms
22,656 KB
testcase_18 AC 57 ms
20,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void getAns(int n)
    {
        var st = new Stack<int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++)
        {
            if (line[i] == "+")
            {
                var w = st.Pop() + st.Pop();
                st.Push(w);
            }
            else if (line[i] == "-")
            {
                var w = -st.Pop() + st.Pop();
                st.Push(w);
            }
            else st.Push(int.Parse(line[i]));
        }
        Console.WriteLine(st.Pop());
    }
}
0