为什么会错?
查看原帖
为什么会错?
1037981
封禁用户楼主2023/7/24 06:33
#include<bits/stdc++.h>
using namespace std;
int main(){
	char ch;
	int a;
	stack<int> s;
	while(cin>>ch&&ch!='@'){
		if(ch>='0'&&ch<='9'){
			a=a*10+ch-'0';
		}
		if(ch=='.'){
			s.push(a);
			a=0;
		}
		if(ch=='+'||ch=='-'||ch=='*'||ch=='/'){
			int x=s.top();
			s.pop();
			int y=s.top();
			s.pop();
			if(ch=='+') s.push(x+y);
			if(ch=='-') s.push(y-x);
			if(ch=='*') s.push(x*y);
			if(ch=='/') s.push(y/x);
		}
	}
	cout<<s.top();
}
2023/7/24 06:33
加载中...