阅读背景:

求后缀表达式的值

来源:互联网 
#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;
}#include<cstdio>
#include<cstdlib>
#include<cst



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: