UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201548#3495. exprJosephcheng100111ms1968kbC++11517b2024-02-01 09:33:432024-02-01 12:11:53

answer

#include<bits/stdc++.h>
using namespace std;

int T,pos,len;
char s[1000005];
int stk[1000005];

void solve()
{
	pos=0;
	scanf("%s",s+1);
	for(len=1;s[len+1]!='\0';len++);
	for(int i=1;i<=len;i++){
		if(s[i]=='0'||s[i]=='1'){stk[++pos]=(s[i]-'0');continue;}
		if(s[i]=='!') {stk[pos]=(!stk[pos]);continue;}
		int R=stk[pos--],L=stk[pos--];
		if(s[i]=='&') stk[++pos]=L&R;
		if(s[i]=='|') stk[++pos]=L|R;
	}
	printf("%d\n",stk[pos]);
}

int main()
{
	scanf("%d",&T);
	while(T--)
		solve();
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 8ms
memory: 1888kb

input:

11
1011|10|0|1||01|11|1||100|10||||010|10||11|10|0|000|11|||001|10|||0110|11|||011||101||||000||||00...

output:

1
1
1
1
1
1
1
1
1
1
0

result:

ok 11 lines

Test #2:

score: 10
Accepted
time: 9ms
memory: 1888kb

input:

11
00&01&00&1&&10&11&00&1&&&&0010&&0&&0011&01&&0&10&&&01&10&0&0&1&1&&01&00&00000&00&&11&00&&&01111&1...

output:

0
0
0
0
0
0
0
0
0
0
1

result:

ok 11 lines

Test #3:

score: 10
Accepted
time: 13ms
memory: 1968kb

input:

10
1!1&11&01|10|01|||01&00&!0|0!11&11&!&|01!|1!&&0!11!|000&00||00!|||!&10!&||11|00&|!&!1|10&01&1!|0!...

output:

0
1
1
0
0
1
0
0
0
0

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 13ms
memory: 1964kb

input:

10
1!0!|00|01|0!0!&&!0!11!&00!&|||110|1!!|00!&1!&|0!10&00||01|11|0110!|!&|||1&0!0!&0&11!01&00||&0!1!...

output:

1
1
1
0
0
1
0
0
0
1

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 11ms
memory: 1960kb

input:

10
1!0!&10&0!!!|1!1!&&10|00|00|01&01&11|0!|1!&|!|00&01&00|1!!&0!1|1!&0!1!&!!010&00|&|&|00!&00&00|0!|...

output:

1
0
0
0
1
0
0
1
0
1

result:

ok 10 lines

Test #6:

score: 10
Accepted
time: 12ms
memory: 1964kb

input:

10
11|0!!10&10&&!0!1!|!|!0!&11|00||10&11&00!|&!11&00|00|00|&01&11|1&|0!0!00!&!||!!|&!&00|00|0!0!&1!1...

output:

0
1
0
0
1
1
0
1
1
1

result:

ok 10 lines

Test #7:

score: 10
Accepted
time: 12ms
memory: 1968kb

input:

10
1!0!|0&111&10&!10!&&&!&1!10&11|0|0!|!10!|0!||0!0!||111&00&&||!|101&11&&&011!|!10!||!&&0!1!&1!0&&!...

output:

1
0
1
1
0
0
1
1
1
1

result:

ok 10 lines

Test #8:

score: 10
Accepted
time: 6ms
memory: 1964kb

input:

10
01!|0!&010!1||00&00|0&!&0!&11|1!!|!&!1!11|01&&|111!1|0||&001&11&&&11!&!|1!&110!&0|0!|&1!0!01!|&|!...

output:

1
0
1
1
0
1
1
1
0
0

result:

ok 10 lines

Test #9:

score: 10
Accepted
time: 14ms
memory: 1964kb

input:

10
11!&!1!011|11|&0|0!|||1!111|10|&0|!01|00&01&10&001|00|1|&&0!1!&00|10|0|&0!0!|&|&|01!&0!&01!11|11&...

output:

0
0
0
1
1
0
0
1
1
0

result:

ok 10 lines

Test #10:

score: 10
Accepted
time: 13ms
memory: 1964kb

input:

10
11&0!!0!1&!0!0!0|||&111!&|1!0&1&&&10|0!!100|10&11&0!!|!|0!10!|||&1!1|0!1!|&0!01|11&|!&11|11&00&0!...

output:

1
1
0
1
1
1
0
0
0
1

result:

ok 10 lines