全紫求助
查看原帖
全紫求助
491523
rpmcppAFOed楼主2021/12/5 16:55
#include<bits/stdc++.h>
using namespace std;
stack<int> stk;
char ch;
int main(){
	while(cin>>ch){
		if(ch='.')
			continue;
		if(ch>='0'&&ch<='9'){
			int tmp=ch-'0';
			stk.push(tmp);
		}
		if(ch=='+'){
			int p1=stk.top();
			stk.pop();
			int p2=stk.top();
			stk.pop();
			stk.push(p1+p2);
		}
		if(ch=='-'){
			int p1=stk.top();
			stk.pop();
			int p2=stk.top();
			stk.pop();
			stk.push(p2-p1);
		}
		if(ch=='*'){
			int p1=stk.top();
			stk.pop();
			int p2=stk.top();
			stk.pop();
			stk.push(p1*p2);
		}
		if(ch=='/'){
			int p1=stk.top();
			stk.pop();
			int p2=stk.top();
			stk.pop();
			stk.push(p2/p1);
		}
	}
	cout<<stk.top();
	return 0;
}
2021/12/5 16:55
加载中...