请问大佬能帮我看一下哪错了吗?好像有2个符号连一起时就是错的
查看原帖
请问大佬能帮我看一下哪错了吗?好像有2个符号连一起时就是错的
474261
hquhxiehdaohren楼主2021/1/22 21:36
#include <iostream>
#include<string>
#include<stack>
#include<cctype>
using namespace std;

int main()
{
    string s;
    cin>>s;
    stack<int> st;int a(0);
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='@') break;

        if(isdigit(s[i]))
        {

            a*=10;
            a+=(s[i]-'0');
        }
        if(s[i]=='.')
        {
            st.push(a);
            a=0;
        }
        int c,j;


        if(s[i]=='+'){c=st.top();st.pop(); j=st.top();st.push(c+j);}
        if(s[i]=='-') {c=st.top();st.pop(); j=st.top();st.push(j-c);}
        if(s[i]=='*') {c=st.top();st.pop(); j=st.top();st.push(c*j);}
       if(s[i]=='/') {c=st.top();st.pop(); j=st.top();st.push(j/c);}

    }
    cout<<st.top()<<endl;

    return 0;
}

2021/1/22 21:36
加载中...