UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205738#1691. 逆波兰表达式wsh02201000ms1160kbC++859b2024-07-19 18:16:282024-07-19 20:10:16

answer

#include <bits/stdc++.h>
using namespace std;
long long stk[1000005];
long long i=0,now=0;
char op;
int main(){
    
    while((op=getchar())!=EOF)
	{
        if(op>='0'&&op<='9') now*=10,now+=op-'0';
        else if(op==' ')
		{
			if(now>0)
			{
				stk[i+1]=now;
				now=0;
				i++;
			}
            
        }
        else if(op=='+')
		{
            stk[i-1]=stk[i-1]+stk[i];
            stk[i]=0;
            i--;        }
        else if(op=='-')
		{
            stk[i-1]=stk[i-1]-stk[i];
            stk[i]=0;
            i--;
        }
        else if(op=='*')
		{
            stk[i-1]=stk[i-1]*stk[i];
            stk[i]=0;
            i--;
        }
        else if(op=='/')
		{
            stk[i-1]=stk[i-1]/stk[i];
            stk[i]=0;
            i--;
        }
    }
    cout<<stk[1];
	return 0;
}

详细

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

Test #1:

score: 20
Accepted
time: 0ms
memory: 1160kb

input:

23 456 239 + + 123 874 908 345 * - + + 23 44 664 * - +

output:

-340738

result:

ok single line: '-340738'

Test #2:

score: 20
Accepted
time: 0ms
memory: 1160kb

input:

1 2 3 4 - * + 5 6 * -

output:

-31

result:

ok single line: '-31'

Test #3:

score: 20
Accepted
time: 0ms
memory: 1156kb

input:

1 2 + 3 4 5 - * -

output:

6

result:

ok single line: '6'

Test #4:

score: 20
Accepted
time: 0ms
memory: 1156kb

input:

1 2 + 5 4 + *

output:

27

result:

ok single line: '27'

Test #5:

score: 20
Accepted
time: 0ms
memory: 1156kb

input:

35 26 - 28 5 + * 6 7 * -

output:

255

result:

ok single line: '255'