全RE求助
查看原帖
全RE求助
297566
Tan_Wei_Ye楼主2021/3/5 16:29

样例#1下载下来本地跑没问题,但交上去全REkk

自己调了半天也没调出来

代码:

#include<bits/stdc++.h>
#define int long long
const int P=998244353;
using namespace std;
const int N=200;
int n,ans;
string s,e[N];
int pde(char x)
{
	if(x=='(') return 0;
	if(x=='+' || x=='-') return 1;
	if(x=='*') return 2;
	if(x=='^') return 3;
}
int calc(char c,int x,int y)
{
	swap(x,y);
	if(c=='+') return (x+y)%P;
	if(c=='-') return (x-y)%P;
	if(c=='*') return (x*y)%P;
	else 
	{
		int res=1;
		for(int i=1;i<=y;i++)
			res=res*x%P;
		return res;
	}
}
int sub(string t,int a)
{
	stack<char> op;
	stack<int> num;
	int x=-1;
	for(int i=0;i<t.size();i++)
	{
		if(isdigit(t[i])) 
		{
			if(x==-1) x=t[i]-48;
			else x=(x<<1)+(x<<3)+(t[i]-48);
		}
		else if(t[i]=='a')
		{
			num.push(a);
		}
		else if(t[i]=='(')
		{
			op.push(t[i]);
		}
		else if(t[i]==')')
		{
			if(x!=-1) num.push(x);
			x=-1;
			while(op.top()!='(')
			{
				char c=op.top();op.pop();
				int x1=num.top();num.pop();
				int x2=num.top();num.pop();
				num.push(calc(c,x1,x2));
			}
			op.pop();
		}
		else
		{
			if(x!=-1) num.push(x);
			x=-1;
			if(op.top()!='(') 
			{
				int p=pde(t[i]);
				while(pde(op.top())>=p)
				{
					char c=op.top();op.pop();
					int x1=num.top();num.pop();
					int x2=num.top();num.pop();
					num.push(calc(c,x1,x2));
				}
			}
			op.push(t[i]);
		}
		
	}
	return num.top();
}
void read(string &temp)
{
	temp="(((((((((((((((((((((((((((";
	while(1)
	{
		char ch=getchar();
		if(ch=='\n') break;
		if(ch==' ') continue;
		temp=temp+ch;
	}
	temp=temp+")";
}
signed main()
{
	read(s);
	cin>>n;
	getchar();
	ans=sub(s,777);
	for(int i=0;i<n;i++)
	{
		string e;
		read(e);
		if(sub(e,777)==ans) cout<<char(i+'A');
	}
}
2021/3/5 16:29
加载中...