风水戏诸侯 @ 2019-01-21 17:20:01
注意除法需要归为整形!!!切记
by Luban @ 2019-01-21 17:47:46
AC代码:(抄袭?变棕吧!)
#include<bits/stdc++.h>
using namespace std;
int a[1000],*top;
char s[1000];
void push(int x)
{
*top=*top+1;
a[*top]=x;
}
void pop()
{
a[*top]=0;
*top=*top-1;
}
int main()
{
top=&a[0];
scanf("%s",s);
int i=0,r=1,j,ans,y,z;
while(i<strlen(s))
{
if (s[i]=='.')
{
ans=0;
r=1;
j=i-1;
while(s[j]>='0'&&s[j]<='9'&&j>=0)
{
ans=ans+r*(s[j]-'0');
r=r*10;
j=j-1;
}
push(ans);
}
if (s[i]=='@')
{
cout<<a[1]<<endl;
return 0;
}
if (s[i]=='+')
{
y=a[*top];
z=a[*top-1];
pop();
pop();
push(y+z);
}
if (s[i]=='-')
{
y=a[*top];
z=a[*top-1];
pop();
pop();
push(z-y);
}
if (s[i]=='*')
{
y=a[*top];
z=a[*top-1];
pop();
pop();
push(y*z);
}
if (s[i]=='/')
{
y=a[*top];
z=a[*top-1];
pop();
pop();
push(z/y);
}
i=i+1;
}
}
by difficult @ 2019-05-19 11:19:50
数据都是整型吗?
by y_kx_b @ 2022-08-22 11:34:44
@Light_Of_Wisdom tlqtj 烤谷*3