全RE!求调

P1449 后缀表达式

luu0_0 @ 2024-09-09 22:20:08

#include<bits/stdc++.h>
 using namespace std;
class MyStack{
    int* data;
    int topindex;//topindex
    int size;
public:
    MyStack();
    ~MyStack();
    bool empty();
    bool push(int value);
    bool pop();
    int top();
    int getsize();  
};
MyStack::MyStack(){
    data=new int[10001];
    topindex=-1;
    size=0;
}
MyStack::~MyStack(){
    delete[]data;
    topindex=-1;
    size=0;
}
bool MyStack::push(int value){
    if(topindex>=10000)return false;
    data[++topindex]=value;
    size++;
    return true;
}
bool MyStack::pop(){
    if(empty())return false;
    topindex--;
    size--;
    return true;
}
int MyStack::top(){
    if (empty())return 0; 
    return data[topindex];
}
bool MyStack::empty(){
    return topindex==-1;
}
int MyStack::getsize(){
    return size;
}
 int main(){
    MyStack stack;
    char q;
    cin>>q;
    int now=0;
    while(q!='@'){//两位数怎么解决 
        if(q>='0'&&q<='9'){
            q=q-'0';
            now*=10;
            now+=q;
         }else if(q=='.'){
            stack.push(now);
            now=0;
         }else if(q=='+'){
            int op1=stack.top();
            stack.pop();
            int op2=stack.top();
            stack.pop();
            stack.push(op1+op2);
         }else if(q=='-'){
            int op1=stack.top();
            stack.pop();
            int op2=stack.top();
            stack.pop();
            stack.push(op2-op1);
         }else if(q=='*'){
            int op1=stack.top();
            stack.pop();
            int op2=stack.top();
            stack.pop();
            stack.push(op1*op2);
         }else if(q=='/'){
            int op1=stack.top();
            stack.pop();
            int op2=stack.top();
            stack.pop();
            stack.push(op2/op1);
         }
         cin>>q;
     }
    now=stack.top();
    cout<<now;
    stack.pop();
    stack.~MyStack();
    return 0;
 }

by sgy_always_ac @ 2024-09-19 17:29:03

dalao但是数组应开char!


|