| 比赛 |
2026初中综合小练习 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
| 题目名称 |
逻辑表达式 |
最终得分 |
100 |
| 用户昵称 |
李金泽 |
运行时间 |
0.335 s |
| 代码语言 |
C++ |
内存使用 |
4.21 MiB |
| 提交时间 |
2026-04-14 21:17:53 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<stack>
#define N 1000005
#define int long long
#define ul unsigned long long
#define db double
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define mem(x) memset(x,0,sizeof(x));
using namespace std;
int T,n,m,k,ans,op,x,y,z;
char c[N];
struct node{int a,b,c;};
stack<int>a;
stack<node>b;
void swap(int &x,int &y){int t=x;x=y;y=t;}
int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
void mg(){
int c;node x,y;
y=b.top();b.pop();
x=b.top();b.pop();
c=a.top();a.pop();
if(c==1){
if(!x.a)b.push({0,x.b+1,x.c});
else b.push({x.a&y.a,x.b+y.b,x.c+y.c});
}
else{
if(x.a)b.push({1,x.b,x.c+1});
else b.push({x.a|y.a,x.b+y.b,x.c+y.c});
}
}
signed main(){
freopen("expr.in","r",stdin);freopen("expr.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>c+1;n=strlen(c+1);
fo(i,1,n){
switch(c[i]){
case '0':{
b.push({0,0,0});
break;
}
case '1':{
b.push({1,0,0});
break;
}
case '&':{
while(a.size()&&a.top()>=1)mg();
a.push(1);
break;
}
case '|':{
while(a.size()&&a.top()>=0)mg();
a.push(0);
break;
}
case '(':{
a.push(-1);
break;
}
case ')':{
while(a.size()&&a.top()!=-1)mg();
a.pop();
break;
}
}
}
while(a.size())mg();
cout<<b.top().a<<'\n'<<b.top().b<<' '<<b.top().c;
return 0;
}