C++49分求助
查看原帖
C++49分求助
690669
Beacon_wolf楼主2023/11/11 16:58
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
char ch,x,a,b;
int main() {
    while(ch!='@')
    {
        ch = getchar();
        if(ch >= '0' && ch <= '9') x = x * 10 + ch - '0';
        else if(ch == '.') {s.push(x);x = 0;}
        else{
            switch(ch)
            {
                case '+':a = s.top();s.pop();b = s.top();s.pop();s.push(a + b);break;
                case '-':a = s.top();s.pop();b = s.top();s.pop();s.push(b - a);break;
                case '*':a = s.top();s.pop();b = s.top();s.pop();s.push(a * b);break;
                case '/':a = s.top();s.pop();b = s.top();s.pop();s.push(b / a);break;
            }
        }
    }
    cout << s.top();
    return 0;
}
2023/11/11 16:58
加载中...