結果

問題 No.49 算数の宿題
ユーザー TAKEKATSUTAKEKATSU
提出日時 2019-03-30 15:58:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,421 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 170,356 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:41:27
合計ジャッジ時間 2,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b)) * b;
}

int main(){
 
  string s; cin >> s;
  vector<int> v;

  int temp = 0;

  queue<char> q;

  for(int i = 0; i < s.length(); i++)
  {
    if(s[i] >= '0' and s[i] <= '9'){
      if(temp == 0)
        temp = s[i] - '0';
      
      else temp = temp * 10 + s[i] - '0';
    }
    else{
      if(s[i] == '*')
        q.push('+');
      else if(s[i] == '+')
        q.push('*');
      v.pb(temp);
      temp = 0;
    }
  }
  v.pb(temp);
  int cnt = 1;
  ll ans = v[0];

  while(!q.empty()){
    
    char c = q.front(); q.pop();

    if(c == '+')
      ans += v[cnt];
    else
      ans *= v[cnt];
    cnt ++; 

  }

  pr(ans);

  return 0;
}
0