@[Max_FWL](/user/638491)
<https://www.luogu.com.cn/discuss/669364>
>小粉兔:getline 之后如果最后一个字符是 \r,要删掉
>
>应该就对了
by lianchanghua_YYDS @ 2024-02-04 22:26:05
@[lianchanghua_YYDS](/user/919528) thx
by Illus1onary_Real1ty @ 2024-02-04 22:32:54
等下等下,不知道是我代码实现有问题是什么,好像还是错的
by lianchanghua @ 2024-02-04 22:38:19
@[Max_FWL](/user/638491) 对不起,实力有限,只能 50 pts 了
```cpp
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 30;
const int MOD = 1e9 + 7;
int n, len[N], flg[N];
string s[N];
stack<int> Number;
stack<char> Opt;
int Quick_Pow(int x, int y){
int res = 1;
while (y){
if (y & 1)
res *= x, res %= MOD;
x *= x, x %= MOD;
y >>= 1;
}
return res;
}
int Level(char op){
if (op == '(')
return 0;
if (op == ')')
return 1;
if (op == '+' || op == '-')
return 2;
if (op == '*')
return 3;
return 4;
}
int Solve(int x, int a){
while (!Number.empty())
Number.pop();
while (!Opt.empty())
Opt.pop();
for (int i = 1; i <= len[x]; i++){
if (s[x][i] >= '0' && s[x][i] <= '9'){
int now = 0;
while (s[x][i] >= '0' && s[x][i] <= '9')
now = now * 10 + s[x][i]-'0', i++;
Number.push(now);
}
if (s[x][i] == 'a'){
Number.push(a);
continue;
}
if (s[x][i] == ' ' || s[x][i]== '\r' )
continue;
if (s[x][i] == '(')
Opt.push(s[x][i]);
else{
while (Level(Opt.top()) >= Level(s[x][i])){
int x = Number.top();
Number.pop();
int y = Number.top(), z;
Number.pop();
if (Opt.top() == '+')
z = x + y;
else if (Opt.top() == '-')
z = y - x + MOD;
else if (Opt.top() == '*')
z = x * y;
else z = Quick_Pow(y, x);
Number.push(z % MOD);
Opt.pop();
}
if (s[x][i] == ')')
Opt.pop();
else Opt.push(s[x][i]);
}
}
return Number.top();
}
signed main(){
getline(cin, s[0]);
cin >> n;
len[0] = s[0].length() + 2;
s[0] = " (" + s[0] + ")";
char c=getchar();
if(c=='\r') c=getchar();
for (int i = 1; i <= n; i++){
getline(cin, s[i]);
len[i] = s[i].length() + 2;
s[i] = " (" + s[i] + ")";
}
for (int i = 0; i <= 10; i++){
int st = Solve(0, i);
for (int j = 1; j <= n; j++)
if (Solve(j, i) != st)
flg[j] = 1;
}
for (int i = 1; i <= n; i++)
if (!flg[i])
cout << (char)(i-1 + 'A');
cout << endl;
return 0;
}
```
by lianchanghua @ 2024-02-04 23:10:40