提交时间:2024-08-21 13:04:16
运行 ID: 180247
#include <bits/stdc++.h> using namespace std; long long a[100002]; bool b[100001]; int main() { string str; int i, t = 0, top = 0; long long sum = 0; cin >> str; int len = str.size(); for (i = 0; i < len; ++i) if (str[i] == '+') { a[++top] = t; t = 0; } else if (str[i] == '*') { a[++top] = t; t = 0; b[top] = true; } else t = t * 10 + str[i] - '0'; a[++top] = t; for (i = 1; i <= top; ++i) if (b[i]) { a[i + 1] = a[i] * a[i + 1] % 10000; a[i] = 0; } for (i = 1; i <= top; ++i){ sum = (sum + a[i]) % 10000; } cout << sum; return 0; }