ybt 1962

#include<iostream>
#include<cstdio>
#include<stack>
#include<string>
using namespace std;
stack<int>p1;
stack<char>p2;
int n;
string s;
int main() {
	int a,b;
	char ch;
	cin>>a;
	a=a%10000;
	p1.push(a);
	while(cin>>ch) {
		cin>>b;
		b=b%10000; 
		if(ch=='*'){
			a=p1.top();p1.pop();//如果ch为*,a来表示栈内的值并推出该值,在推入a*b%10000的值
			p1.push(a*b%10000);
		}
		else{
			p1.push(b);
			p2.push(ch);
		}
	}
	while(!p2.empty()){
		//ch=p2.top();改行可有可无,因为题中已经说明只有+,*。只剩+,一次一个一个推出表示相加的次数
        p2.pop();//上述一样将站内相邻的两数用a,b存下,并推出栈,再将两数之和推入其中
		a=p1.top();p1.pop();
		b=p1.top();p1.pop();
		p1.push((a+b)%10000);
	}
	a=p1.top(); 
	cout<<a%10000;
	return 0;
}

 

posted @ 2022-05-21 19:29  半喜  阅读(35)  评论(0)    收藏  举报