結果

問題 No.49 算数の宿題
ユーザー chlo27chlo27
提出日時 2018-12-20 00:37:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 768 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 164,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:40:55
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  string s;
  cin >> s;
  int ans=0;
  string tmp;
  bool plus = true;
  allrep(S, s){
    if(S=='*' || S=='+'){
      plus ? ans+=stoi(tmp) : ans*=stoi(tmp);
      S=='*' ? plus=true : plus=false;
      tmp.clear();
    }else{
      tmp += S;
    }
  }
  plus ? ans+=stoi(tmp) : ans*=stoi(tmp);
  cout << ans << endl;
  return 0;
}
0