第一个点RE了不知道为啥
查看原帖
第一个点RE了不知道为啥
1109463
godess楼主2024/8/7 20:23
#include <iostream>
#include<stack>
#include<string>
using namespace std;
int main() {
    stack<int> t;
    string s;
    bool is = 0;
    int cnt = 0;
    int ans=0;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '+') {
            if (is) {
                int n = t.top();
                t.pop();
                t.push((stoi(s.substr(cnt, i - cnt)) * n)%10000);
                cnt = i + 1;
                is = 0;
            }
            else {
                t.push(stoi(s.substr(cnt, i - cnt)) % 10000);
                cnt = i + 1;
            }
            
        }
        else if (s[i] == '*') {
            if (is) {
                int n = t.top();
                t.pop();
                t.push((stoi(s.substr(cnt, i - cnt)) * n) % 10000);
                cnt = i + 1;
            }
            else {
                t.push(stoi(s.substr(cnt, i - cnt)) % 10000);
                cnt = i + 1;
            }
            is = 1;
        }
    }if (s.rfind("+") > s.rfind("*")) {
        ans += stoi(s.substr(s.rfind("+") + 1))%10000;
    }
    else {
        t.top()*= stoi(s.substr(s.rfind("*") + 1))%10000;
    }
    while (!t.empty()) {
        ans += t.top()%10000;
        t.pop();
    }
    ans %= 10000;
    cout << ans;
    
} ```
2024/8/7 20:23
加载中...