问题标题: 酷丁编程:逆波兰表达式2

0
0
王一诺
王一诺
修练者
修练者

题目链接: 酷丁编程:11498

#include<bits/stdc++.h>
using namespace std;
int n;
string s;
stack<int> st;
int toint(string s)
{
    int x;
    stringstream ss;
    ss<<s;
    ss>>x;
    return x;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        if(s=="+")
        {
            int x=st.top();
            st.pop();
            int y=st.top();
            st.pop();
            st.push(x+y);
        }
        else if(s=="*")
        {
            int x=st.top();
            st.pop();
            int y=st.top();
            st.pop();
            st.push(y*x); 
        }
        else
        {
            st.push(toint(s));
        }
    }
    cout<<st.top();
}

 各位大佬,我真球球了,我错哪了呀?

答疑老师今天是放假了吗,问半天没回答。


0
0
0
我要回答