• <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

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

            中綴表達式轉(zhuǎn)化為后綴表達式

            //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();//用于將中綴表達式放入結(jié)構(gòu)體數(shù)組,從而實現(xiàn)數(shù)字與運算符的分離;

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

                   
            void showthepos();

            }
            ;

             

            void Aeasyproblem::inputtheformula()

            {

                   cin
            >>temp;

            }


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

            {

                   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()//這是用于將中綴表達式轉(zhuǎn)化成后綴表達式的函數(shù)

            {

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

                   
            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)  編輯 收藏 引用

            久久久久亚洲av无码专区导航| 久久被窝电影亚洲爽爽爽| 国产精品99久久精品| 狠狠色丁香婷婷久久综合不卡| 成人久久免费网站| 久久精品国产AV一区二区三区| 欧美黑人激情性久久| 国产一区二区三区久久精品| 亚洲av成人无码久久精品 | 91久久国产视频| 日本精品久久久久影院日本| 亚洲AV伊人久久青青草原| 久久一本综合| 亚洲∧v久久久无码精品| 亚洲精品美女久久久久99| 久久青青色综合| 国产99久久久国产精品~~牛| 亚洲欧洲久久av| 亚洲狠狠综合久久| 久久99精品久久久久久噜噜| 欧美牲交A欧牲交aⅴ久久 | 久久久免费精品re6| 97久久天天综合色天天综合色hd | 欧美久久综合性欧美| 久久精品国产亚洲AV不卡| 少妇人妻综合久久中文字幕| 国产精品久久久久乳精品爆| 久久国产精品二国产精品| 无码人妻久久一区二区三区蜜桃| 伊人久久大香线蕉综合网站 | 亚洲av成人无码久久精品| 国产精品视频久久| 久久久久人妻一区精品果冻| 99久久人妻无码精品系列蜜桃| 伊人久久无码精品中文字幕| 久久免费的精品国产V∧| 欧美久久精品一级c片片| 久久久黄色大片| 亚洲伊人久久大香线蕉苏妲己| 日本久久久久久久久久| 精品久久久久久国产潘金莲|