从暑假就一直在调qwq 记录
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=100005;
string s1,s2;
ll n;
ll top,top1,top2,st1[N],q[N];
bool flag;
struct node
{
ll ch;
bool digit;
}st2[N];
inline ll lev(ll ch)
{
if(ch=='^') return 3;
if(ch=='*'||ch=='/') return 2;
if(ch=='+'||ch=='-') return 1;
return 0;
}
inline ll power(ll a,ll b)
{
ll ans=1;
for(ll e=b;e;e>>=1,a*=a)
if(e&1) ans*=a;
return ans;
}
inline string read()
{
string s;
char ch=getchar();
while(ch!=EOF&&ch!='\r'&&ch!='\n')
{
if(ch!=' ') s+=ch;
ch=getchar();
}
return s;
}
inline ll check(string s,ll x)
{
top1=0,top2=0,top=0;
ll len=s.size();
memset(st1,0,sizeof(st1));
memset(st2,0,sizeof(st2));
memset(q,0,sizeof(q));//清空!!!!
for(int i=0;i<len;i++)
{
if(s[i]=='a')
{
st2[++top2]=(node){x,1};
continue;
}
if(isdigit(s[i]))
{
ll f=0;
while(isdigit(s[i]))
f=f*10+s[i++]-'0';
i--;
st2[++top2]=(node){f,1};
continue;
}
if(s[i]=='(')
{
st1[++top1]=s[i];
continue;
}
if(s[i]==')')
{
while(st1[top1]!='(') st2[++top2].ch=st1[top1--];
top1--;
continue;
}
if(top1==0||st1[top1]=='(')
{
st1[++top1]=s[i];
continue;
}
if(lev(s[i])>lev(st1[top1]))
{
st1[++top1]=s[i];
continue;
}
if(lev(s[i])<=lev(st1[top1]))
{
while(lev(s[i])<=lev(st1[top1])) st2[++top2].ch=st1[top1--];
st1[++top1]=s[i];
continue;
}
}
while(top1>0) st2[++top2].ch=st1[top1--];
for(int i=1;i<=top2;i++)
{
if(st2[i].digit) q[++top]=st2[i].ch;
else
{
if(st2[i].ch=='+') q[top-1]+=q[top],top--;
if(st2[i].ch=='-') q[top-1]-=q[top],top--;
if(st2[i].ch=='*') q[top-1]*=q[top],top--;
if(st2[i].ch=='/') q[top-1]/=q[top],top--;
if(st2[i].ch=='^') q[top-1]=power(q[top-1],q[top]),top--;
}
}
return q[top];
}
int main()
{
//freopen("kkkkk.out","w",stdout);
s1=read();
cin>>n; char ch=getchar();
for(int i=1;i<=n;i++)
{
s2=read();
flag=0;
for(int j=1;j<=10;j++)
{
if(check(s1,j)!=check(s2,j))
{
flag=1;
break;
}
}
if(!flag) putchar(('A'-1+i));
}
return 0;
}