2 solutions

  • 1
    @ 2026-7-27 19:02:25
    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    stack<LL> s;
    void solve(char c){
    	LL b=s.top();
    	s.pop();
    	LL a=s.top();
    	s.pop();
    	if(c=='+'){
    		s.push(a+b);
    	}
    	else if(c=='-'){
    		s.push(a-b);
    	}
    	else if(c=='*'){
    		s.push(a*b);
    	}
    	else{
    		s.push(a/b);
    	}
    }
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr);
    	string n;
    	getline(cin,n);
    	int m=n.size();
    	for(int i=0;i<m;i++){
    		if(n[i]==' ') continue;
    		else if(n[i]=='@') break;
    		else if(n[i]>='0'&&n[i]<='9'){
    			LL x=0;
    			int j=i;
    			while(j<=m&&n[j]>='0'&&n[j]<='9'){
    				x=x*10+n[j]-'0';
    				j++;
    			}
    			j--;
    			s.push(x);
    			i=j;
    		}
    		else{
    			solve(n[i]);
    		}
    	}
    	cout<<s.top();
    	return 0;
    }
    

    Information

    ID
    170
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    101
    Accepted
    23
    Uploaded By