部分分骗分代码样例不过,求解
查看原帖
部分分骗分代码样例不过,求解
1033086
HP_Serenity楼主2024/12/27 17:36

本人菜鸡代码,求调(部分分):

#include <bits/stdc++.h>
using namespace std;
stack<int> uqe;
string s;
int n, a[100005], q, op;
int main() {
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	getline(cin, s);
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	scanf("%d", &q);
	while(q --) {
		scanf("%d", &op);
		int tmp = a[op];
		a[op] = !a[op];
		int cnt = 0;
		for(int i=0; i<s.size(); i++) {
			if(s[i]=='x') uqe.push(a[++ cnt]);
			else if(s[i]=='|') {
				int tmp = uqe.top(); uqe.pop();
				int tmp1 = uqe.top(); uqe.pop();
				int ans;
				if(tmp==0&&tmp1==0) ans = 0;
				else ans = 1;
				uqe.push(ans);
				//printf("%d or %d\n", tmp, tmp1);
			} else if(s[i]=='&') {
				int tmp = uqe.top(); uqe.pop();
				int tmp1 = uqe.top(); uqe.pop();
				int ans;
				if(tmp==1&&tmp1==1) ans = 1;
				else ans = 0;
				//printf("%d and %d\n", tmp, tmp1);
				uqe.push(ans);
			} else if(s[i]=='!') {
				int tmp = uqe.top();
				uqe.pop();
				tmp = !tmp;
				uqe.push(tmp);
				//printf("not %d\n", tmp);
			}
		}
		a[op] = !a[op];
		printf("%d\n", uqe.top());
		while(!uqe.empty()) uqe.pop();
	}
	return 0;
}
2024/12/27 17:36
加载中...