3、am>#include#include#include#definepi3.141592654doublecalculate(std::string);intmain(){.專業(yè).整理.下載可編輯//輸入式子,存于s中std::strings;std::getline(std::cin,s);//拋出異常try{//判斷是否有異常字符conststd::stringjubge="1234567890tansincos+-*/^%(
4、)loglnlgsqrtpi!";for(constauto&i:s)if(jubge.fin
5、d(i)==-1)throw1;////拋出異常//將三角函數(shù)名化為數(shù)字與&字符,便于識(shí)別和計(jì)算//以及將對(duì)數(shù)函數(shù)······//以及階乘·········//以及開方·········//將pi/π化為數(shù)字size_tn=0;while((n=s.find("sin"))!=-1)s.replace(n,3,"1&");while((n=s.find("cos"))!=-1)s.replace(n,3,"2&");.專業(yè).整理.下載可編輯while((n=s.find("tan"))!=-1)s.replace(n,3,"3&");while((n=s.find("
6、ln"))!=-1)s.replace(n,2,"4&");while((n=s.find("lg"))!=-1)s.replace(n,2,"5&");while((n=s.find("sqrt"))!=-1)s.replace(n,4,"6&");while((n=s.find("log"))!=-1)s.replace(n,3,"@");while((n=s.find("!"))!=-1)s.replace(n,1,"$7");while((n=s.find("pi"))!=-1)s.replace(n,2,std::to_string(pi));//去除括號(hào)w
7、hile(s.find("(")!=-1
8、
9、s.find(")")!=-1){std::ostringstreamuout;//存儲(chǔ)未處理字符autoleft=s.begin();//記錄左括號(hào)位置autoright=s.begin();//記錄右括號(hào)位置while(right!=s.end()){//處理最里層括號(hào)里的字符if(*right=='('){.專業(yè).整理.下載可編輯if(*left=='('){for(autoi=left;i!=right;++i)uout<<*i;}left=right;}elseif(*right==')'){if(*left!='
10、(')throw2;////拋出異常uout<