比赛 板子大赛 评测结果 AAAAAAAAAA
题目名称 表达式求值 最终得分 100
用户昵称 AeeE5x 运行时间 0.138 s
代码语言 C++ 内存使用 5.24 MiB
提交时间 2025-01-22 13:10:20
显示代码纯文本
#include<iostream> 
#include<stack>
#include<vector>
using namespace std;
string s;
vector<string> ve;

int typ(string x){
    if(x=="*") return 3;
    if(x=="+") return 2;
    return 1;
}

int tnum(string x){
	int res=0;
	for(int i=0;i<x.length();i++) res=(res*10+x[i]-'0')%10000;
	return res;
}

stack<int> st;

int main(){
    freopen("expr2013.in","r",stdin);
    freopen("expr2013.out","w",stdout);
    
    cin>>s;
    string nw;
    for(int i=0;i<s.length();i++){
        if(s[i]=='+'||s[i]=='*') ve.push_back(nw),ve.push_back(s.substr(i,1)),nw="";
        else nw+=s[i];
    }
    ve.push_back(nw);
    
    bool nd=0;
    for(int i=0;i<ve.size();i++){
    	if(typ(ve[i])==1){
    		st.push(tnum(ve[i]));
    		if(nd){
    			int a=st.top();st.pop();
    			int b=st.top();st.pop();
    			st.push((a*b)%10000);
    			nd=0;
			}
		}else if(typ(ve[i])==3) nd=1;
	}
	int ans=0;
    while(st.size()) ans=(ans+st.top())%10000,st.pop();
    printf("%d",ans);
    
    
    return 0;
}