比赛 |
CSP2022普及组 |
评测结果 |
WWWWEEWEEEEEEEWWWEEE |
题目名称 |
逻辑表达式 |
最终得分 |
0 |
用户昵称 |
hnzzlza |
运行时间 |
2.585 s |
代码语言 |
C++ |
内存使用 |
10.31 MiB |
提交时间 |
2022-10-29 17:58:38 |
显示代码纯文本
- #include <bits/stdc++.h>
- using namespace std;
- string s;int hz[1000005],tp;
- int str[1000005],top,_a,_o,yxj[128];
- void instr(char c){
- if(c=='0'||c=='1'){hz[tp++]=c-'0';return;}
- else {
- tp-=2;
- if(c=='&'){
- if(hz[tp]==0){_a++;hz[tp]=0;}
- else hz[tp]=(hz[tp])&(hz[tp+1]);
- }
- if(c=='|'){
- if(hz[tp]==1){_o++;hz[tp]=1;}
- else hz[tp]=(hz[tp])|(hz[tp+1]);
- }
- }
- }
- void zzh(){
- for(int i=0;i<s.size();++i){
- if(s[i]=='1'||s[i]=='0')instr(s[i]);
- else if(s[i]=='(')str[top++]=s[i];
- else if(s[i]=='&'||s[i]=='|'){
- if(yxj[str[top]]<yxj[s[i]])str[top++]=s[i];
- else {
- while(yxj[str[top]]>=yxj[s[i]])instr(char(str[--top]));
- str[top++]=s[i];
- }
- }
- else if(s[i]==')'){
- while(char(str[top-1])!='('){
- instr(char(str[--top]));
- }
- top--;
- }
- }
- while(top>0)instr(char(str[--top]));
- }
- int main(){
- freopen("csp2022pj_expr.in","r",stdin);
- freopen("csp2022pj_expr.out","w",stdout);
- yxj['(']=1;yxj['|']=2;yxj['&']=3;
- cin>>s;
- zzh();
- cout<<hz[1]<<endl<<_a<<' '<<_o;
- return 0;
- }