比赛 CSP2022普及组 评测结果 C
题目名称 逻辑表达式 最终得分 0
用户昵称 李奇文 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-10-29 17:34:30
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
char c;
struct result{
	int v,ande,ore;
};
result operator&(result x,result y){
	if(x.v==0){
		return {x.v&y.v,x.ande+1,x.ore};
	}else{
		return {x.v&y.v,x.ande+y.ande,x.ore+y.ore};
	}
}
result operator|(result x,result y){
	if(x.v==1){
		return {x.v|y.v,x.ande,x.ore+1};
	}else{
		return {x.v|y.v,x.ande+y.ande,x.ore+y.ore};
	}
}
result solve(){
	result ret,mul;
	result t;
	ret,v=1;
	mul.v=0;
	while(cin>>c){
		if(c=='('){
			t=solve();
		} 
		if(c==1||c==0) t={c,0,0};
		if(c=='|'){
			mul=mul|t;
			ret=ret|mul;
			mul.ore=1;		
		}
		if(c=='&'){
			mul=mul&t;
		}
		if(c==')'){
			mul=mul|t;
			ret=ret|mul;
			return ret;
		}
	} 
	mul=mul|t;
	ret=ret|mul;
	return ret;
}
int main(){
	freopen("csp2022pj_expr.in","r",stdin);
	freopen("csp2022pj_expr.out","w",stdout);
	result ans=solve();
	cout<<ans.v<<endl;
	cout<<ans.ande<<" "<<ans.ore;
	return 0;
}