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

            94久久国产乱子伦精品免费| 久久99国产精品99久久| 97久久婷婷五月综合色d啪蜜芽| 久久99精品久久久久子伦| 人人狠狠综合久久亚洲高清| 狠狠色丁香久久婷婷综合| 久久久久人妻一区精品| 国产亚洲色婷婷久久99精品| 99久久精品久久久久久清纯| 久久综合久久鬼色| 蜜桃麻豆www久久| 久久精品这里热有精品| 模特私拍国产精品久久| 国内精品久久久久久久影视麻豆| 亚洲精品乱码久久久久久蜜桃图片| 成人精品一区二区久久久| 国产精品免费福利久久| 久久婷婷色综合一区二区| 亚洲欧美精品一区久久中文字幕| 国产一区二区精品久久凹凸| 久久综合给久久狠狠97色| 久久亚洲精品中文字幕| 亚洲国产精品无码久久98| AV无码久久久久不卡蜜桃| 亚洲av日韩精品久久久久久a| 伊人久久大香线蕉AV一区二区| 亚洲国产日韩欧美久久| 中文国产成人精品久久亚洲精品AⅤ无码精品| 久久久久亚洲AV综合波多野结衣| 久久国产午夜精品一区二区三区| 久久久无码精品午夜| 亚洲伊人久久成综合人影院 | 一97日本道伊人久久综合影院| 久久久久人妻一区精品| 伊人久久大香线蕉综合网站| 久久精品中文字幕有码| 久久中文字幕人妻熟av女| 日韩欧美亚洲综合久久| 99国产欧美精品久久久蜜芽| 97精品伊人久久大香线蕉app| 亚洲精品高清久久|