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

            色欲综合久久中文字幕网| 久久精品国产WWW456C0M| 久久91精品国产91久久小草 | 好属妞这里只有精品久久| 偷窥少妇久久久久久久久| 久久无码国产| 伊人久久精品影院| 亚洲国产精品成人久久蜜臀 | 欧美午夜精品久久久久久浪潮| 久久精品www| 伊人久久大香线蕉精品| 狠狠色丁香婷综合久久| 国产麻豆精品久久一二三| 久久国产精品一国产精品金尊| 亚洲国产精品成人久久| 久久综合狠狠综合久久综合88| 国内精品久久久久影院薰衣草| 久久乐国产综合亚洲精品| 性做久久久久久久久浪潮| 怡红院日本一道日本久久| 久久久久国产视频电影| 久久久久久极精品久久久| 2021国内久久精品| 久久亚洲欧美国产精品 | 免费观看成人久久网免费观看| 日韩精品国产自在久久现线拍 | 色播久久人人爽人人爽人人片AV| 精品乱码久久久久久久| 999久久久国产精品| 国产高清国内精品福利99久久| 久久青青草原精品国产| 国产精品99久久99久久久| 久久精品国产亚洲AV无码偷窥| 麻豆AV一区二区三区久久| 久久A级毛片免费观看| 久久亚洲私人国产精品vA| 色婷婷综合久久久久中文 | 国产精品乱码久久久久久软件| 无码人妻久久一区二区三区蜜桃| 亚洲精品美女久久久久99小说| 亚洲欧洲精品成人久久曰影片 |