求后缀表达式的值

来源:互联网 发布:光环大数据和达内 编辑:程序博客网 时间:2024/05/16 07:25
#include<cstdio>#include<cstdlib>#include<cstring>int stack[101];char s[256];int comp(char s[256]){   int i=0,top=0,x,y;   while(i<=strlen(s)-2){switch (s[i]){         case '+':stack[--top]+=stack[top+1]; break;         case '-':stack[--top]-=stack[top+1]; break;         case '*':stack[--top]*=stack[top+1]; break;         case '/':stack[--top]/=stack[top+1]; break;         default:x=0; while (s[i]!=' ') x=x*10+s[i++]-'0'; stack[++top]=x; break;      }      i++;    }    return stack[top];}int main(){              printf("input a string(@_over):");  gets(s);  printf("result=%d",comp(s));  return 0;}

0 0