結果

問題 No.49 算数の宿題
ユーザー twice_l
提出日時 2018-12-08 22:30:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 768 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 159,344 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 02:00:55
合計ジャッジ時間 2,065 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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