后缀表达式

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
char s[301],p[301];
int q[301];
int len,j,ret = 0;
int main()
{
while(1)
{
s[++len] = getchar();
if(s[len] == '@') break;
if(s[len] >= '0' && s[len] <= '9') ret = ret * 10 + (s[len] - '0');
if(s[len] == ' ' && s[len - 1] >= '0' && s[len - 1] <= '9')
{
q[++j] = ret;
ret = 0;
}
if(s[len] == '+') q[--j] = q[j] + q[j + 1];
if(s[len] == '-') q[--j] = q[j] - q[j + 1];
if(s[len] == '*') q[--j] = q[j] * q[j + 1];
if(s[len] == '/') q[--j] = q[j] / q[j + 1];
}
printf("%d\n",q[j]);
return 0;
}

posted @ 2018-01-21 10:43  CaptainLi  阅读(151)  评论(0编辑  收藏  举报