代码没翻到……但是这个是我们老师写的代码,像AI吗?
#include <bits/stdc++.h>
using namespace std;
#define F(i, j, k) for (int i = j; i <= k; ++i)
#define DF(i, j, k) for (int i = j; i >= k; --i)
const int N = 1e5 + 100;
int num[N];
string st;
bool tp[N];
inline void solve1(int l, int r) {
F(i, l, r) {
if (i == l || st[i - 1] == '*')
st[i] = '9';
if (i > l && st[i - 1] == '/')
st[i] = '1';
}
}
queue<vector<pair<int, int>>> a[N];
int mx;
inline void solve0(int l, int r) {
int sum = 0;
F(i, l, r) if (st[i] == '/')++ sum;
if (!sum) {
F(i, l, r) if (st[i] == '?') st[i] = '1';
return;
}
F(i, l, r) {
if (i == l)
st[i] = '1';
if (st[i] == '/')
st[i + 1] = '9';
if (st[i] == '*')
st[i + 1] = '1';
}
vector<pair<int, int>> v;
v.emplace_back(make_pair(l, r));
mx = max(mx, sum);
a[sum].push(v);
}
inline void jian(int l, int r) {
F(i, l, r) if (st[i] == '/' && st[i + 1] == '9') {
st[i + 1] = '1';
break;
}
}
int main() {
freopen("C.in", "r", stdin);
freopen("C.out", "w", stdout);
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> st;
int len = int(st.size());
int cnt = 0;
num[++cnt] = -1;
tp[cnt] = 1;
for (int i = 0; i < len; ++i) {
if (st[i] == '+') {
num[++cnt] = i;
tp[cnt] = 1;
}
if (st[i] == '-') {
num[++cnt] = i;
tp[cnt] = 0;
}
}
num[++cnt] = len;
F(i, 1, cnt - 1) {
if (tp[i])
solve1(num[i] + 1, num[i + 1] - 1);
else
solve0(num[i] + 1, num[i + 1] - 1);
}
++mx;
while (mx > 1) {
mx--;
while (a[mx].size() >= 9) {
vector<pair<int, int>> now;
F(i, 1, 9) {
for (auto it : a[mx].front())
now.emplace_back(it);
a[mx].pop();
}
if (mx > 1)
a[mx - 1].push(now);
}
if ((mx > 1 && a[mx - 1].empty() && !a[mx].empty()) ||
a[mx].size() == 1) {
while (!a[mx].empty()) {
for (auto it : a[mx].front())
jian(it.first, it.second);
if (mx > 1)
a[mx - 1].push(a[mx].front());
a[mx].pop();
}
continue;
}
if (!a[mx].empty()) {
vector<pair<int, int>> now;
for (auto it : a[mx].front())
st[it.first] = char(48 + 10 - a[mx].size());
while (!a[mx].empty()) {
for (auto it : a[mx].front())
now.emplace_back(it);
a[mx].pop();
}
if (mx > 1)
a[mx - 1].push(now);
}
}
cout << st << '\n';
}