結果

問題 No.49 算数の宿題
ユーザー izryt(趣味)
提出日時 2016-01-19 01:52:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 545 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 158,316 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 01:48:20
合計ジャッジ時間 2,003 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int ans = 0, val = 0;
char op = '*';
bool f = true;

void calc()
{
    if (op == '+') ans *= val;
    if (op == '*') ans += val;
    val = 0;
}

int main()
{
    string e; cin >> e;

    for (int i = 0; i < e.size(); ++i) {
        if (e[i] == '+') {
            calc();
            op = '+';
        } else if (e[i] == '*') {
            calc();
            op = '*';
        } else {
            val *= 10;
            val += e[i] - '0';
        }
    }

    calc();

    cout << ans << endl;
}
0