• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            中綴表達式轉化為后綴表達式

            //Copyright by abilitytao

            //All right not reserved!!

             

             

            #include 
            <process.h>

            #include 
            <iostream.h>

            #include 
            <conio.h>

            #include 
            <stdlib.h>

            #include 
            <math.h>

            #include 
            <stack>

            #include 
            <cstring>

            #include 
            <ctype.h>

            using namespace std;

             

            struct formula

            {

                   
            char numormark[100];

            }
            ;

             

            /**////////////////////////////////////////////////////////////

            /////////////////////定義problem類/////////////////////////

            ///////////////////////////////////////////////////////////


             

            class Aeasyproblem

            {

            private:

                   
            int formulalen;

                   
            char temp[1000];

                   formula 
            in[1000];

                   formula pos[
            1000];

            public:

                   
            void inputtheformula();

                   
            void intoin();//用于將中綴表達式放入結構體數組,從而實現數字與運算符的分離;

                   
            void intopos();//用于將中綴表達式轉化成后綴表達式;

                   
            void showthepos();

            }
            ;

             

            void Aeasyproblem::inputtheformula()

            {

                   cin
            >>temp;

            }


            void Aeasyproblem::intoin()//這是用于解析輸入的字符串的函數,將算式中的每個個體存入自己聲明的結構體中;

            {

                   formulalen
            =0;

                   
            int templen;

                   
            int temlen;

                   
            char tem[100];

             

                  

                   templen
            =strlen(temp);

                   
            int i;

                   
            int j;

                   j
            =0;

                   
            for(i=0;i<templen;i+=temlen)

                   
            {

                          
            if(isdigit(temp[i]))

                          
            {

                                 sscanf(
            &temp[i],"%[^-^+^*^/^(^)]",tem);

                                 temlen
            =strlen(tem);

                                 strcpy(
            in[j].numormark,tem);

                                 formulalen
            ++;

                                 j
            ++;

                          }


                          
            else

                          
            {

                                 temlen
            =1;

                                 
            in[j].numormark[0]=temp[i];

                                 
            in[j].numormark[1]='\0';

                                 formulalen
            ++;

                                 j
            ++;

                          }


                   }


            }


             

             

             

             

            void Aeasyproblem::intopos()//這是用于將中綴表達式轉化成后綴表達式的函數

            {

                   
            /**//////////////////'(' ')''+''-''*''/''='

                   
            static int isp[7]=0,19,12,12,13,13,0};

                   
            static int icp[7]={20,19,12,12,13,13,0};

                   
            int precedence_sta;

                   
            int precedence_token;

             

                   stack
            <formula>sta;

                   
            int i;

                   
            int j;

                   
            char token[100];

                   formula start;

                   strcpy(start.numormark,
            "\0");

                   sta.push(start);

                   j
            =0;

                   
            for(i=0;i<formulalen;i++)

                   
            {

                         

                          strcpy(token,
            in[i].numormark);

                          
            if(strcmp(token,"\0")==0)

                                 
            break;

                          
            if(isdigit(token[0]))

                          
            {

                                 strcpy(pos[j].numormark,token);

                                 j
            ++;

                          }


                          
            else if(strcmp(token,")")==0)

                          
            {

                                 
            while(strcmp(sta.top().numormark ,"(")!=0)

                                 
            {

                                        strcpy(pos[j].numormark,sta.top().numormark);

                                        j
            ++;

                                        sta.pop();

                                 }


                                 sta.pop();

                          }


                          
            else

                          
            {

                                        
            if(strcmp(sta.top().numormark,"(")==0)

                                               precedence_sta
            =0;

                                        
            if(strcmp(sta.top().numormark,")")==0)

                                               precedence_sta
            =19;

                                        
            if(strcmp(sta.top().numormark,"+")==0)

                                               precedence_sta
            =12;

                                        
            if(strcmp(sta.top().numormark,"-")==0)

                                               precedence_sta
            =12;

                                        
            if(strcmp(sta.top().numormark,"*")==0)

                                               precedence_sta
            =13;

                                        
            if(strcmp(sta.top().numormark,"/")==0)

                                               precedence_sta
            =13;

                                        
            if(strcmp(sta.top().numormark,"\0")==0)

                                               precedence_sta
            =0;

                                        
            if(strcmp(token,"(")==0)

                                               precedence_token
            =20;

                                        
            if(strcmp(token,")")==0)

                                               precedence_token
            =19;

                                        
            if(strcmp(token,"+")==0)

                                               precedence_token
            =12;

                                        
            if(strcmp(token,"-")==0)

                                               precedence_token
            =12;

                                        
            if(strcmp(token,"*")==0)

                                               precedence_token
            =13;

                                        
            if(strcmp(token,"/")==0)

                                               precedence_token
            =13;

                                        
            if(strcmp(token,"\0")==0)

                                               precedence_token
            =0;

                                 
            while(precedence_sta>=precedence_token)

                                 
            {

                                               pos[j]
            =sta.top();

                                               j
            ++;

                                               sta.pop();

                                        
            if(strcmp(sta.top().numormark,"(")==0)

                                               precedence_sta
            =0;

                                        
            if(strcmp(sta.top().numormark,")")==0)

                                               precedence_sta
            =19;

                                        
            if(strcmp(sta.top().numormark,"+")==0)

                                               precedence_sta
            =12;

                                        
            if(strcmp(sta.top().numormark,"-")==0)

                                               precedence_sta
            =12;

                                        
            if(strcmp(sta.top().numormark,"*")==0)

                                               precedence_sta
            =13;

                                        
            if(strcmp(sta.top().numormark,"/")==0)

                                               precedence_sta
            =13;

                                        
            if(strcmp(sta.top().numormark,"\0")==0)

                                               precedence_sta
            =0;

                                        
            if(strcmp(token,"(")==0)

                                               precedence_token
            =20;

                                        
            if(strcmp(token,")")==0)

                                               precedence_token
            =19;

                                        
            if(strcmp(token,"+")==0)

                                               precedence_token
            =12;

                                        
            if(strcmp(token,"-")==0)

                                               precedence_token
            =12;

                                        
            if(strcmp(token,"*")==0)

                                               precedence_token
            =13;

                                        
            if(strcmp(token,"/")==0)

                                               precedence_token
            =13;

                                        
            if(strcmp(token,"\0")==0)

                                               precedence_token
            =0;

                                 }


                                 strcpy(start.numormark,token);

                                

                                        sta.push(start);

                          }


                   }


                   
            while(strcpy(token,sta.top().numormark))

             

                   
            {

                          
            if(strcmp(token,"\0")==0)

                                 
            break;

                          pos[j]
            =sta.top();

                          j
            ++;

                          sta.pop();

                   }


                   strcpy(pos[j].numormark,
            "\0");

             

            }


             

            void Aeasyproblem::showthepos()

            {

                   
            int i;

                   
            for(i=0;strcmp(pos[i].numormark,"\0")!=0;i++)

                   
            {

                         

                          cout
            <<pos[i].numormark<<' ';

             

                   }


                   cout
            <<'\b'<<endl<<endl;

                  

            }


            /**////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////Problem類定義完成/////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////////


             

             

             

            int main ()

            {

                   Aeasyproblem justforfun;

                   
            while(1)

                   
            {

                          justforfun.inputtheformula();

                          justforfun.intoin();

                          justforfun.intopos();

                          justforfun.showthepos();

                   }


                   
            return 0;

            }

            posted on 2009-07-14 16:37 abilitytao 閱讀(401) 評論(0)  編輯 收藏 引用

            色婷婷综合久久久久中文| 久久国产精品成人片免费| 久久99国产一区二区三区| 精品人妻久久久久久888| 中文字幕久久欲求不满| 色偷偷88欧美精品久久久| 久久精品一区二区三区中文字幕| 久久精品国产WWW456C0M| 伊色综合久久之综合久久| 日产精品久久久久久久性色| 久久久久久国产精品免费无码| 精品九九久久国内精品| 久久久久久免费视频| 国内精品久久久久影院一蜜桃 | 久久丝袜精品中文字幕| 一本色道久久88—综合亚洲精品| 国产69精品久久久久777| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 亚洲乱码精品久久久久..| 99精品国产在热久久| 99久久香蕉国产线看观香| 国产精品美女久久久| 国产激情久久久久久熟女老人 | 久久久久久a亚洲欧洲aⅴ| 亚洲午夜无码AV毛片久久| 久久精品国产一区二区 | 99久久er这里只有精品18| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 国产高潮久久免费观看| 久久精品这里热有精品| 亚洲精品无码久久久久sm| 综合久久一区二区三区 | 人妻无码αv中文字幕久久| 久久只有这精品99| 狠狠色丁香久久婷婷综合蜜芽五月| 一本一道久久精品综合| 国产亚洲综合久久系列| 国产一久久香蕉国产线看观看| 久久99亚洲网美利坚合众国| 久久中文骚妇内射| 国产精品天天影视久久综合网|