蒟蒻求助(呜呜呜~)
查看原帖
蒟蒻求助(呜呜呜~)
725794
BBY123楼主2024/3/21 16:37
#include<iostream>
#include<stack>
#include<string>
using namespace std;
stack<int> z;
long long ans,a;
char h;
string s;
int main(){
	cin>>s;
	for(int i = 0;i <= s.size();i++){
        if(s[i]>='0'&&s[i]<='9'){
        	a*=10;
			a+=s[i]-'0';
		}
        else if(s[i]=='.'){
            z.push(a);
            a=0;
    	}
    	if(s[i]=='@'){
    		cout<<ans<<endl;
    		return 0;
		}
    	else{
    		if(s[i]=='+'){
				ans+=z.top();
				z.pop();
			}
			else if(s[i]=='-'){
				ans+=z.top();
				z.pop();
				ans=z.top()-ans;
				z.pop();
			}
			else if(s[i]=='*'){
				ans*=z.top();
				z.pop();
			}
			else if(s[i]=='/'){
				ans+=z.top();
				z.pop();
				ans=z.top()/ans;
				z.pop();
			}
		}
    }
	return 0;
} 

谢谢

2024/3/21 16:37
加载中...