CSP-J的T3RE是怎么回事
  • 板块灌水区
  • 楼主0htoAi
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/11/8 11:22
  • 上次更新2023/11/5 08:30:07
查看原帖
CSP-J的T3RE是怎么回事
335366
0htoAi楼主2020/11/8 11:22

代码如下

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

int n,m;
int q;
bool x[100005];
int main()
{
//	freopen("expr.in","r",stdin);
//	freopen("expr.out","w",stdout);
	string s;	
	getline(cin,s);
//	getline(cin,meiyong);
//	cout<<s;
	scanf("%d",&n);
//	cout<<s<<" "<<n;
	
	
	for (register int i=1;i<=n;++i)
	{
		cin>>x[i];
	}
	scanf("%d",&q);
	
	for (int i=1;i<=q;i++)
	{	
		stack<bool>k;
		int t;
		scanf("%d",&t);
		for (register int j=0;j<s.length();++j)
		{
			
			
			if(s[j]>='1'&&s[j]<='9'&&(j+1==s.length()||s[j+1]==' '))
			{
				int ii=j,z=0,wei=1;
			
				while (s[ii]>='1'&&s[ii]<='9')
				{
				
					z+=((int)s[ii]-48)*wei;
					wei*=10;
					ii--;
				}
		//		cout<<z<<" ";
				if(z==t)
				{
				k.push(!x[z]);	
				}
				else
				{
				k.push(x[z]);
				}
			//	cout<<z<<" ";
		//	cout<<"cin>>"<<k.top()<<endl;
		
			}
		//	cout<<j;
		
			if(s[j]=='!')
			{
				bool z=k.top();
			//	cout<<"!"<<z<<endl;
				k.pop();
				k.push(!z);
			}
			if(s[j]=='|')
			{
				bool z1=k.top();
				k.pop();
				bool z2=k.top();
				k.pop();
			//	cout<<z1<<" | "<<z2<<endl;
				k.push(z1|z2);
			}
			if(s[j]=='&')
			{
				bool z1=k.top();
				k.pop();
				bool z2=k.top();
				k.pop();
			//	cout<<z1<<" & "<<z2<<endl;
				k.push(z1&z2);
			}
		//	cout<<j<<" ";
		}
		cout<<k.top()<<endl;
	//	cout<<endl;
	}	
	return 0;
	
}
2020/11/8 11:22
加载中...