20分求调
查看原帖
20分求调
1152154
Chinami_Nagisa楼主2024/8/29 23:36

只过了1,4

#include<iostream>
#include<string>
#include<stack>
using namespace std;
string s;
typedef long long LL;
stack<LL> st;
LL sum;
int main(){
    cin>>s;
    bool b=0;
    for(int i=0;i<s.size();i++)
    {
        LL t=0;
        while(s[i]>='0'&&s[i]<='9')
        {
            t*=10;
            t+=(s[i]-'0');
            i++;
        }
        if(b==0) st.push(t);
        else
        {
            LL m=st.top();
            st.pop();
            st.push(m*t);
            b=0;
        }
        if(i>=s.size()) break; 
        if(s[i]=='+') continue;
        if(s[i]=='*') b=1;
    }
    while(!st.empty())
    {
        LL temp=st.top();
        st.pop();
        sum+=temp;
        sum%=10000;
    }
    cout<<sum;
}
2024/8/29 23:36
加载中...