时间限制
400 ms
内存限制
64 MB
#include <iostream>
#include <map>
using namespace std;
map<int, int> ma;
int main() {
string s;
cin >> s;
s += "+";
int n = int(s.size());
int now = 0, last = 0;
bool ok = true, dd = false;
int mx = 0, mi = 0;
for (int i = 0; i < n; ++ i) {
if (s[i] == 'd' || s[i] == '+' || s[i] == '-') {
if (s[i] == 'd') {
if (now == 0) now = 1;
last = now;
now = 0;
dd = true;
} else {
if (dd) {
ma[now] += last;
if (ok) {
mx += now * last;
mi += last;
} else {
mx -= last;
mi -= now * last;
}
} else {
if (ok) {
mx += now;
mi += now;
} else {
mx -= now;
mi -= now;
}
}
now = 0;
last = 0;
if (s[i] == '+') ok = true;
else ok = false;
dd = false;
}
} else {
now = now * 10 + (s[i] - '0');
}
}
for (auto x : ma) {
cout << x.first << ' ' << x.second << endl;
}
cout << mi << ' ' << mx;
}