UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211528#1691. 逆波兰表达式ylq022100ms0kbC++11503b2024-08-15 18:55:242024-08-15 18:55:40

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)
	{
		int ans=0;
		if(c[0]>='0'&&c[0]<='9'){
			for(int i=c.size()-1;i>=0;i++) ans=ans*10+c[i];
			st.push(ans);
		}
		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
Runtime Error

input:

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

output:


result:


Test #2:

score: 0
Runtime Error

input:

1 2 3 4 - * + 5 6 * -

output:


result:


Test #3:

score: 0
Runtime Error

input:

1 2 + 3 4 5 - * -

output:


result:


Test #4:

score: 0
Runtime Error

input:

1 2 + 5 4 + *

output:


result:


Test #5:

score: 0
Runtime Error

input:

35 26 - 28 5 + * 6 7 * -

output:


result: