




如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
#include<stdio.h> #include<iostream> #include<string> #include<stack> #include<map> #include<stdlib.h> #include<cstring> usingnamespacestd; charnifix_expre[200];//存放中缀表达式 stringsuffix_expre;//后缀表达式,最后转换成constchar* map<string,double>string_num;//用于将表达式中各个数字映射成单个字符+'\0' map<char,int>out;//外部优先级 map<char,int>in;//内部优先级 stack<char>operation; stack<string>num; stack<string>temp; charop[7]={'+','-','*','/','#','(','('}; stringsnum[11]={"a","b","c","d","e","f","g","h","i","j","k"}; boolisnotoperation(chara) { if(a=='+'||a=='-'||a=='*'||a=='/'||a=='#'||a=='('||a==')') returnfalse; returntrue; } voidprechange(char*a) { intj=0; intlength=strlen(a); //cout<<i; stringnew_nifix; /* for(inti=0;i<length;i++) { if((*(a+i)=='+'||*(a+i)=='-'||*(a+i)=='*'||*(a+i)=='/')&&*(a+i+1)=='-') { for(intj=length;j>i+1;j--) { *(a+j)=*(a+j-1); } *(a+i+1)='0'; length++; } } cout<<a<<endl; */ for(inti=0;i<length;i++) { stringanum; while(isnotoperation(*(a+i))) { anum+=*(a+i); i++; } stringkk; if(strlen(anum.c_str())) { doublebnum=atof(anum.c_str()); string_num[snum[j]]=bnum; kk=snum[j++]; } new_nifix=new_nifix+kk+*(a+i); } //测试输出处理的数字 cout<<new_nifix<<endl; map<string,double>::iteratorit=string_num.begin(); for(;it!=string_num.end();it++) cout<<it->first<<""<<it->second<<endl; strcpy(a,new_nifix.c_str()); } voidchange(char*a) { intn=strlen(a); for(inti=0;i<n;i++) { if(isnotoperation(*(a+i))) { stringkk; kk+=*(a+i); num.push(kk); //cout<<"shuzi"<<kk<<endl; } else { if(operation.empty()) operation.push(*(a+i)); else { if(out[*(a+i)]>in[operation.top()]) operation.push(*(a+i)); elseif(out[*(a+i)]==in[operation.top()]) { operation.pop(); } elseif(out[*(a+i)]<in[operation.top()]) { while(out[*(a+i)]<in[operation.top()])//此处切记切记加循环!!! { chartemp_oper=operation.top(); operation.pop(); stringkk; kk+=temp_oper; temp.push(kk); for(intm=0;m<2;m++) { kk=num.top(); num.pop(); temp.push(kk); } kk=temp.top(); temp.pop(); for(intm=0;m<2;m++) { kk+=temp.top(); temp.pop(); } num.push(kk); //cout<<kk<<endl; } if

王子****青蛙
实名认证
内容提供者


最近下载