17分 4wa 1ac 1re 1pt stack求助
查看原帖
17分 4wa 1ac 1re 1pt stack求助
785141
badcow楼主2022/12/31 15:26
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int k;
char a[110];
stack<int>s;
int main(){
    scanf("%s",a);
    int l=strlen(a),i=0;
    while(l--){
        if(a[i]>='0'&&a[i]<='9'){
            k*=10;
            k+=a[i]-'0';
        }
        if(a[i]=='+'){
            int t1=s.top();
            s.pop();
            int t2=s.top();
            s.pop();
            s.push(t1+t2);
        }
        if(a[i]=='-'){
            int t1=s.top();
            s.pop();
            int t2=s.top();
            s.pop();
            s.push(t1-t2);
        }
        if(a[i]=='*'){
            int t1=s.top();
            s.pop();
            int t2=s.top();
            s.pop();
            s.push(t1*t2);
        }
        if(a[i]=='/'){
            int t1=s.top();
            s.pop();
            int t2=s.top();
            s.pop();
            s.push(t1/t2);
        }
        if(a[i]=='.'){
            s.push(k);
            k=0;
        }
        i++;
    }
    int t=s.top();
    printf("%d",t);
    return 0;
}//
2022/12/31 15:26
加载中...