deamoon_2 @ 2019-01-30 21:24:51
33分,咋了?
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<cstring>
using namespace std;
int main()
{
stack<int >a;
int x,i;
char s[101];
cin>>s;
for(i=0;i<strlen(s);i++)
{
if(s[i]<='9'&&s[i]>='1')
{
x=s[i]-'0';
i++;
while(s[i]<='9'&&s[i]>='1')
{
x=x*10+s[i]-'0';
i++;
}
a.push(x);
}
else
{
if(s[i]=='+')
{
x=a.top();
a.pop();
x+=a.top();
a.pop();
a.push(x);
}
else if(s[i]=='-')
{
x=a.top();
a.pop();
x=a.top()-x;
a.pop();
a.push(x);
}
else if(s[i]=='*')
{
x=a.top();
a.pop();
x*=a.top();
a.pop();
a.push(x);
}
else if(s[i]=='/')
{
x=a.top();
a.pop();
x=a.top()/x;
a.pop();
a.push(x);
}
}
}
cout<<a.top();
return 0;
}
by xunJason @ 2019-01-30 21:32:59
while(s[i]<='9'&&s[i]>='1')错了是 while(s[i]<='9'&&s[i]>='0')
by xunJason @ 2019-01-30 21:34:25
@陈俊安cja
by deamoon_2 @ 2019-01-30 21:35:58
@xunJason 谢谢