PJ T3 这样写能得几分
  • 板块灌水区
  • 楼主LYR_
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/11/7 14:14
  • 上次更新2023/11/5 08:38:47
查看原帖
PJ T3 这样写能得几分
110319
LYR_楼主2020/11/7 14:14
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1e5+10;
string s;
int n,a[N];
int main() {
	freopen("expr.in","r",stdin);
	freopen("expr.out","w",stdout);
	getline(cin,s);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int q;
	cin>>q;
	while(q--) {
		int x,t;
		cin>>x;
		t=a[x];
		if(a[x]==0) a[x]=1;
		else a[x]=0;
		stack<int> st;
		for(int i=0;i<(int)s.size();i++) {
			if(s[i]==' ') continue;
			if(s[i]=='x') {
				int sum=0;
				i++;
				while(s[i]>='0' && s[i]<='9') {
					sum=sum*10+s[i]-'0';
					i++;
				}
				i--;
				st.push(a[sum]);
			}
			else {
				if(s[i]=='&') {
					int b=st.top();st.pop();
					int c=st.top();st.pop();
					if(b==1 && c==1) st.push(1);
					else st.push(0);
				}
				else if(s[i]=='|') {
					int b=st.top();st.pop();
					int c=st.top();st.pop();
					if(b==0 && c==0) st.push(0);
					else st.push(1);
				}
				else if(s[i]=='!'){
					int b=st.top();st.pop();
					if(b==0) st.push(1);
					else st.push(0);
				}
			}
		}
		int ans=st.top();st.pop();
		cout<<ans<<endl;
		a[x]=t;
	}
	return 0;
}
2020/11/7 14:14
加载中...