結果

問題 No.49 算数の宿題
ユーザー troro_kelp
提出日時 2018-09-20 14:45:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,852 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 101,324 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 01:59:48
合計ジャッジ時間 1,671 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0