#include<bits/stdc++.h>
using namespace std;
int n=0;
string s;
vector<int> num;
int main (){while(getline(cin,s))
{
num.clear();
for(int i=0;i<s.size();i++)
{
if(s[i]==' ')continue;
if(s[i]=='\0')continue;
if(s[i]=='\r')continue;
if(s[i]=='\n')continue;
if(isdigit(s[i]))
{
while(1)
{
n=n*10+s[i]-'0';
if(isdigit(s[i+1]))
i++;
else break;
}
num.push_back(n);
n=0;
}
else {
int b=num.back(); num.pop_back();
int a=num.back(); num.pop_back();
if(s[i]=='*')
num.push_back(a*b);
if(s[i]=='/')
num.push_back(a/b);
if(s[i]=='+')
num.push_back(a+b);
if(s[i]=='-')
num.push_back(a-b);
}
}
cout<<num.back();
}return 0;}
#include
using namespace std;int n=0;
string s;
vector num;int main (){while(getline(cin,s))
{
num.clear();
for(int i=0;i {
if(s[i]==' ')continue;
if(s[i]=='\0')continue;
if(s[i]=='\r')continue;
if(s[i]=='\n')continue;
if(isdigit(s[i]))
{
while(1)
{
n=n*10+s[i]-'0';
if(isdigit(s[i+1]))
i++;
else break;
}
num.push_back(n);
n=0;
}
else {
int b=num.back(); num.pop_back();
int a=num.back(); num.pop_back();
if(s[i]=='*')
num.push_back(a*b);
if(s[i]=='/')
num.push_back(a/b);
if(s[i]=='+')
num.push_back(a+b);
if(s[i]=='-')
num.push_back(a-b);
}
}
cout<}return 0;}
把 n=n*10+s[i]-'0';
改成用 st.push_back(stoi(s));
就好了?_?
#include<bits/stdc++.h>
using namespace std;
string s;
vector<long long> st;
int main (){
while(cin>>s)
{
if(s == "+" || s == "-" || s == "/" || s == "*") {
long long b=st.back(); st.pop_back();
long long a=st.back(); st.pop_back();
if(s == "+") st.push_back(a+b);
if(s == "-") st.push_back(a-b);
if(s == "*") st.push_back(a*b);
if(s == "/") st.push_back(a/b);
}
else
{
st.push_back(stoi(s));
}
}
cout<<st[0]<<'\n';
return 0;}