1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <bits/stdc++.h> using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<string, string> pss;
#define rep(i, a, n) for (int i = a; i < n; ++i) #define per(i, a, n) for (int i = n - 1; i >= a; --i) #define fi first #define se second #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define endl '\n'
vi v; int n, m; string op; int main() { ios::sync_with_stdio(false); int temp; while (cin >> n >> m) { cin >> op; rep(i, 0, n) v.pb(op[i] - '0'); cin >> op; rep(i, 0, m) { if (op[i] == '*') { v.pb(0); } else if (op[i] == '/') { v.pop_back(); } else if (op[i] == '+') { ++v.back(); per(i, 0, v.size()) { if (v[i] == 2) { v[i] = 0; ++v[i - 1]; } else break; } } else if (op[i] == '-') { --v.back(); per(i, 0, v.size()) { if (v[i] < 0) { v[i] = 1; --v[i - 1]; } else break; } } } rep(i, 0, v.size()) { cout << v[i]; } cout << endl; } }
|