http://acm.nyist.net/JudgeOnline/problem.php?pid=267

表达式求值问题。。中缀转化为后缀。。。

#include #include #include #include #include #include #include using namespace std; stack fu; stackshu; stack Q; float cal(float a,float b,char c) { switch(c) { case'+':return a+b; case'-': return a-b; case '*':return a*b; case '/':return a/b; } } int ran(char a) { if(a=='#') return 0; if(a=='('||a==')') return 1; if(a=='+'||a=='-') return 2; if(a=='*'||a=='/') return 3; } void doit() { float frist ,second, result; char c; second=shu.top(); shu.pop(); frist=shu.top(); shu.pop(); c=fu.top(); fu.pop(); result=cal(frist,second,c); shu.push(result); } void sback(string str) { int m=str.size(); string shu1=""; bool flag(false); fu.push('#'); for(int i=0;i0) fu.push(str[i]); else { while(ran(str[i])-ran(fu.top())<=0) { cout<>n; while(n--) { string s; cin>>s; //sfront(s); sback(s); cout<

你可能感兴趣的:(http://acm.nyist.net/JudgeOnline/problem.php?pid=267)