結果

問題 No.49 算数の宿題
ユーザー troro_kelptroro_kelp
提出日時 2018-09-20 14:45:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,852 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 99,540 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:40:00
合計ジャッジ時間 1,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}
ll N, D;
bool dp[10100];
int p[110];
int main() {
	string s; cin >> s;
	stack<int> st;
	s+="b";
	int ans = 0;
	REP(i, s.size()) {
		if (s[i] == '*' || s[i] == '+' || i == s.size()-1) {
			int idx = 1;
			int t = 1, sum = 0;
			while (1) {
				if (i - idx < 0||s[i - idx] == '*' || s[i - idx] == '+' ) break;
				sum += (s[i - idx] - '0')*t;
				t *= 10;
				idx++;
			}
//			cout << sum << endl;
			st.push(sum);
		}
	}
	stack<int> st1;
	while (!st.empty()) {
		st1.push(st.top());
		st.pop();
	}
	REP(i, s.size()) {
		if (s[i] == '*') {
			int p, q; p = st1.top(); st1.pop();
			q = st1.top(); st1.pop();
			st1.push(p + q);
		}
		if (s[i] == '+') {
			int p, q; p = st1.top(); st1.pop();
			q = st1.top(); st1.pop();
			st1.push(p * q);
		}
	}
	cout << st1.top() << endl;
	return 0;
}
0