代码神秘WA,求神犇
查看原帖
代码神秘WA,求神犇
1531031
songyuteng楼主2024/12/1 11:31
#include<bits/stdc++.h>
using namespace std;
stack<long long> sta;
int a[300];
string s;
void jisuan(char c){
	long long x,y;
	if(!sta.empty()){
		x=sta.top();
		sta.pop();
	}
	if(!sta.empty()){
		y=sta.top();
	    sta.pop();
	}
	if(c=='+') sta.push(y+x);
	if(c=='-') sta.push(y-x);
	if(c=='*') sta.push(y*x);
	if(c=='/') sta.push(y/x);
}
int main(){
	getline(cin,s);
	a['+']=1;
	a['-']=1;
	a['*']=2;
	a['/']=2;
	int len=s.size();
	for(int i=0;i<len-1;i++){
		if(s[i]=='@'){
			break;
		}
		if(isdigit(s[i])){
			long long x=s[i]-'0';
			while(i+1<len-1&&isdigit(s[i+1])){
				i++;
				x*=10;
				x+=s[i]-'0';
			}
			sta.push(x);
		}
		else if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'){
			jisuan(s[i]);
		}
	}
	cout<<sta.top();
	return 0;
}
2024/12/1 11:31
加载中...