代码求调
  • 板块学术版
  • 楼主__Aha
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/1/7 23:23
  • 上次更新2023/10/24 05:13:29
查看原帖
代码求调
671779
__Aha楼主2023/1/7 23:23

P1310求调

80分WA2

#include<bits/stdc++.h>
#define mod 10007
using namespace std;
int l,len,work(),fccf();
char s[100010],g[200010];
struct node
{
	int zero,one;
};
stack<char>sz;
stack<node>so; 
int main()
{
	work();
	return 0;
}

int fccf(char x)
{
	if(x=='*') return 1;
	if(x=='+') return 0;
	else return -1; 
}

int work()
{
	cin>>l>>(s+1);
	s[0]='(';
	s[l+1]=')';
	l=strlen(s);
	for(int i=0;i<l;i++)
	{
		if(s[i]=='(')
		{
			sz.push('(');
			if(s[i+1]!='(') g[len++]='_';
		}
		else if(s[i]==')')
		{
			while(!sz.empty()&&sz.top()!='(')
			{
				g[len++]=sz.top();
				sz.pop();
			}
			sz.pop();
		}
		else
		{
			while(!sz.empty()&&fccf(s[i])<=fccf(sz.top()))
			{
				g[len++]=sz.top();
				sz.pop();
			}
			sz.push(s[i]);
			g[len++]='_';
		}
	}
	while(!sz.empty())
	{
		g[len++]=sz.top();
		sz.pop();
	}
//	cout<<g<<endl;
	for(int i=0;i<len;i++)
	{
		if(g[i]=='_')
		{
			so.push(node{-1,-1});
		}
		else
		{
			node t1,t2,t3;
			t1=so.top();so.pop();
			t2=so.top();so.pop();
			if(t1.one==-1) t1=node{1,1};
			if(t2.one==-1) t2=node{1,1};
			if(g[i]=='+')
			{
				t3.zero=t1.zero*t2.zero%mod;
				t3.one=(t1.zero*t2.one%mod+t1.one*t2.zero%mod+t1.one*t2.one)%mod;
			}
			else if(g[i]=='*')
			{
				t3.zero=(t1.zero*t2.one%mod+t1.one*t2.zero%mod+t1.zero*t2.zero)%mod;
				t3.one=t1.one*t2.one%mod;
			}
			so.push(t3);
		}
	}
	node ans=so.top();
	cout<<ans.zero%mod;
	return 0;
}
2023/1/7 23:23
加载中...