中缀表达式转后缀表达式

//"6 9 + 5 3 * - 8 -"
#include <bits/stdc++.h>
using namespace std;
int n,i = 0,a[100];
char a1;
int main(){
    cin>>n;
    while(n--){
        cin>>a1;
        if(a1>='1' && a1<='9'){
            a[++i] = a1-'0';
        }else{
            int x,y,num = 0;
            y = a[i--];
            x = a[i--];
            if(a1=='+'){
                num = x+y;
            }else if(a1=='-'){
                num = x-y;
            }else if(a1=='/'){
                num = x/y;
            }else{
                num = x*y;
            }
            a[++i] = num;
        }
    }
    cout<<a[i];
    return 0;
}
posted @ 2025-07-17 15:50  黛玉醉打将门神  阅读(5)  评论(0)    收藏  举报