結果

問題 No.49 算数の宿題
ユーザー kpinkcatkpinkcat
提出日時 2023-10-10 03:28:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 864 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 105,820 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 03:28:51
合計ジャッジ時間 1,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int main(){
    string s, op1 = "", op2 ="";
    cin >> s;
    ll sum1 = 0, tmp;
    bool first = true;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == '*' || s[i] == '+'){
            op2 = op1;
            op1 = "";
            op1 += s[i];
            tmp = stoll(s.substr(0, i));
            s = s.substr(i+1);
            i = 0;
            if (first){
                sum1 += tmp;
                first = false;
                continue;
            }
            if (op2 == "*") sum1 += tmp;
            else sum1 *= tmp;
        }
    }
    if (op1 == "*") sum1 += stoll(s);
    else sum1 *= stoll(s);
    cout << sum1 << endl;
}
0