#pragma warning(disable:4786) #include<string>#include<map>#include<stack>#include<iostream>#include<ctype.h>using namespace std;v 展开
#pragma warning(disable:4786) #include<string>#include<map>#include<stack>#include<iostream>#include<ctype.h>using namespace std;void main() { map<string, char>table;table["++"]='>';table["+-"]='>';table["+*"]='<';table["+/"]='<';table["+("]='<';table["+)"]='>';table["+#"]='>';table["-+"]='>';table["--"]='>';table["-*"]='<';table["-/"]='<';table["-("]='<';table["-)"]='>';table["-#"]='>';table["*+"]='>';table["*-"]='>';table["**"]='>';table["*/"]='>';table["*("]='<';table["*)"]='>';table["*#"]='>';table["/+"]='>';table["/-"]='>';table["/*"]='>';table["//"]='>';table["/("]='<';table["/)"]='>';table["/#"]='>';table[")+"]='>';table[")-"]='>';table[")*"]='>';table[")/"]='>';table["))"]='>';table[")#"]='>';table["(+"]='<';table["(-"]='<';table["(*"]='<';table["(/"]='<';table["(("]='<';table["()"]='=';table["#+"]='<';table["#-"]='<';table["#*"]='<';table["#/"]='<';table["#("]='<';table["##"]='=';stack<float>num;stack<char>alp;alp.push('#');string s="35*10*50";s+='#';int i=0;char c=s[i++];int tag=0;while(c!='#'||alp.top()!='#') { if(isdigit(c)) { char d=s[i];tag++;if(isdigit(d)) { num.push((float)c-48);} else { num.push((float)c-48);float n=1,m=0;for(int j=tag;j>0;j--) { m=num.top()*n+m;n=n*10;num.pop();} num.push(m);tag=0;} //num.push((float)c-48);//字符转数字 c=s[i++];} else { string s1;s1+=alp.top();s1+=c;char c1=table[s1];switch(c1) { case'<': alp.push(c);c=s[i++];break;case'=': alp.pop();c=s[i++];break;case'>': float y=num.top();num.pop();float x=num.top();num.pop();char c2=alp.top();alp.pop();switch(c2) { case'+': x=x+y;break;case'-': x=x-y;break;case'*': x=x*y;break;case'/': x=x/y;break;} num.push(x);cout<<num.top()<<endl;break;} } } cout<<num.top();} 收起