全re求助
查看原帖
全re求助
1126733
lxc129楼主2024/4/29 21:13
#include<bits/stdc++.h>
using namespace std;
char c;
stack<int>s;
int num,l,r;
int main(){
	while (cin>>c){
		if (c=='@') break;
		if (c>='0' && c<='9') num=num*10+c-'0';
		if (c=='.'){
			s.push(num);
			num=0;
		}
		else{
			l=s.top();
			s.pop();
			r=s.top();
			s.pop();
			switch (c){
				case '+':s.push(l+r);break;
				case '-':s.push(r-l);break;
				case '*':s.push(l*r);break;
				case '/':s.push(r/l);break;
			}
		}
		
	}
	cout<<s.top();
}
2024/4/29 21:13
加载中...