結果

問題 No.49 算数の宿題
ユーザー chakkuchakku
提出日時 2016-04-06 01:20:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 67,632 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:30:45
合計ジャッジ時間 1,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define ALL(v) (v).begin(),(v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void func(int& ans,int& n,char op){
    if(op=='+') ans = ans * n;
    else ans = ans + n;
}

int main(){
    string s; cin>>s;
    int ans = 0;
    int t = 0;
    char op = '*';
    for(int i=0;i<s.size();i++){
        if('0'<=s[i] and s[i]<='9'){
            t = t * 10 + s[i]-'0';
        }
        else if(s[i]=='*'){
            func(ans,t,op);
            op = '*';
            t=0;
        }
        else if(s[i]=='+'){
            func(ans,t,op);
            op = '+';
            t=0;
        }
    }
    func(ans,t,op);
    cout << ans << endl;
}
0