結果

問題 No.49 算数の宿題
ユーザー nemunemunemunemu
提出日時 2024-01-16 06:25:53
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 803 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 113,152 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-16 06:25:59
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.49 算数の宿題
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;

int main() {
    string S;
    cin >> S;
    vector<int> num;
    vector<char> op;
    int now = 0;
    for (auto c: S) {
        if (isdigit(c)) {
            now = 10 * now + (int)(c - '0');
        } else {
            op.push_back(c);
            num.push_back(now);
            now = 0;
        }
    }
    num.push_back(now);
    while (op.size()) {
        int a = *num.begin();
        int b = *(next(num.begin()));
        char o = *op.begin();
        num.erase(num.begin());
        num.erase(num.begin());
        op.erase(op.begin());
        if (o == '*') num.insert(num.begin(), a + b);
        else num.insert(num.begin(), a * b);
    }
    cout << num[0] << endl;
}
0