全RE!求调
查看原帖
全RE!求调
1232657
luu0_0楼主2024/9/9 22:20
#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;
 }
  
2024/9/9 22:20
加载中...