全wa求助dalao
查看原帖
全wa求助dalao
1112575
with_my_moon楼主2024/10/5 15:01
using namespace std;
#define maxn 1008611

int n,q,vc;
int xw[maxn];
char c,cf='0';
stack<char>k;
char ch[maxn];
char ch1[maxn]; 
int cnt=1;

void fin(int whi){
	int ori=xw[whi];
	xw[whi]=!xw[whi];
	for(int i=1;i<=cnt;i++){
		if(ch[i]>'0'&&ch[i]<'9') ch1[i]=xw[ch[i]-'0']+'0';
	}
	/*for(int i=1;i<=cnt;i++){
		cout<<ch1[i]<<" ";
	}
	cout<<endl;*/
	for(int i=1;i<=cnt;i++){
		if(ch1[i]<'0'||ch1[i]>'9'){
			if(ch1[i]=='!'){
				int fr=k.top()-'0';
				fr=!fr;
				k.pop();
				k.push(fr+'0');
				continue;
			}
			else if(ch1[i]=='&'){
				int fr1=k.top()-'0';
				k.pop();
				int fr2=k.top()-'0';
				k.pop();
				int fr=fr1&fr2;
				k.push(fr+'0');
				continue;
			}
			else{
				int fr1=k.top()-'0';
				k.pop();
				int fr2=k.top()-'0';
				k.pop();
				int fr=fr1|fr2;
				k.push(fr+'0');
				continue;
			}
		}
		k.push(ch1[i]);
	}
	int fr=k.top();
	while(!k.empty()) k.pop();
	xw[whi]=ori;
	cout<<fr-'0'<<endl;
	return;
}

int main(){
	while(cin>>c){
		if(c>'0'&&c<'9'){
			if(cf!='x'){
				vc=c-'0';
				break;
			}
			else{
				ch[--cnt]=c;
				cnt++;
				continue;
			}
		}
		ch[cnt]=c;
		cnt++;
		cf=c;
	}
	cnt--;
	for(int i=1;i<=cnt;i++){
		ch1[i]=ch[i];
	}
	/*while(!k.empty()){
		char t=k.top();k.pop();
		cout<<t<<" ";
	}*/
	for(int i=1;i<=vc;i++) cin>>xw[i];
	//for(int i=1;i<=vc;i++) cout<<xw[i]<<" ";cout<<endl;
	/*for(int i=1;i<=cnt;i++){
		cout<<ch[i]<<" ";
	}
	cout<<endl;*/
	cin>>q;
	for(int i=1;i<=q;i++){
		int whic;
		cin>>whic;
		fin(whic);
	}
	return 0;
}
2024/10/5 15:01
加载中...