UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211530#1691. 逆波兰表达式ylq0221601ms1232kbC++11436b2024-08-15 18:57:292024-08-15 18:57:45

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
stack<ll> st;
int main()
{
	ll cnt=0;
	string c;
	while(cin>>c)
	{
		if(c[0]>='0'&&c[0]<='9')
			st.push(c[0]-'0');
		else
		{
			ll y=st.top();
			st.pop();
			ll x=st.top();
			st.pop();
			if(c[0]=='+')
				st.push(x+y);
			else if(c[0]=='-')
				st.push(x-y);
			else if(c[0]=='*')
				st.push(x*y);
		}
	}
	cout<<st.top();
	return 0;
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1232kb

input:

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

output:

-32

result:

wrong answer 1st lines differ - expected: '-340738', found: '-32'

Test #2:

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

input:

1 2 3 4 - * + 5 6 * -

output:

-31

result:

ok single line: '-31'

Test #3:

score: 20
Accepted
time: 1ms
memory: 1224kb

input:

1 2 + 3 4 5 - * -

output:

6

result:

ok single line: '6'

Test #4:

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

input:

1 2 + 5 4 + *

output:

27

result:

ok single line: '27'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 1224kb

input:

35 26 - 28 5 + * 6 7 * -

output:

-35

result:

wrong answer 1st lines differ - expected: '255', found: '-35'