帮忙看一下错题
查看原帖
帮忙看一下错题
507714
woxinbiancheng8888楼主2022/1/16 21:23
#include <iostream>
using namespace std;
int top=0;
int s[1001]; 
void push(int n){
	if(top<299){
		top++;
		s[top]=n;
		return;
	}
}
void pop() {
	if(top>0){
		top--;
	}
}
int gettop(){
	return s[top];
}
void clear(){
	top=0;
}
int main()
{
	int a;
	char b;
	int h;
	int sum=0;
	cin>>a;
	push(a);
	while(cin>>b&&b!='='){
		cin>>a;
		if(b=='+'){
			push(a);
		}else if(b=='-'){
			push(-a);	
		}else if(b=='*'){
			h=gettop();
			pop();
			push(a*h);
		}else if(b=='/'){
			h=gettop();
			pop();
			push(a/h);
		}
	}
	while(top!=0){
		sum+=s[top];
		pop();
	}
	cout<<sum<<endl;
	return 0;
}
2022/1/16 21:23
加载中...