結果

問題 No.49 算数の宿題
ユーザー imulanimulan
提出日時 2016-02-09 18:47:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 834 bytes
コンパイル時間 1,276 ms
コンパイル使用メモリ 145,188 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:28:59
合計ジャッジ時間 1,792 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;

  int n=s.size();

  int i;
  int ans=0;
  int st=0;

  char op='*';
  s+='*';
  rep(i,n){
    if(s[i]=='+' || s[i]=='*'){//演算器号が来たら
      op=s[i];//記号を保存
      st=i+1;
    }
    else{
      if(s[i+1]=='+' || s[i+1]=='*'){
        string t=s.substr(st,i+1-st);
        int tt=atoi(t.c_str());

        if(op=='*') ans+=tt;
        else ans*=tt;

        //cout << t<<endl;
        //printf(" %d: %d\n",i,ans);
      }
    }
  }

  std::cout << ans << std::endl;
  return 0;
}
0