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

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

            Reverse Polish Notation——標程

             

            //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-02-19 13:05 abilitytao 閱讀(773) 評論(0)  編輯 收藏 引用

            一本色道久久88加勒比—综合| 亚洲国产视频久久| 国产69精品久久久久99尤物| 久久亚洲欧洲国产综合| 国产亚洲精品久久久久秋霞| 国内精品久久久久久99蜜桃 | 免费一级欧美大片久久网| 国内精品久久久久影院薰衣草 | 欧美亚洲国产精品久久| 99久久国产热无码精品免费| 久久人人爽人人爽AV片| 精品久久久久久国产潘金莲 | 久久久久久久久久久| 色成年激情久久综合| 午夜精品久久久久久99热| 久久久久国产成人精品亚洲午夜| 久久久噜噜噜www成人网| 久久天天婷婷五月俺也去| 国内精品伊人久久久久网站| 久久婷婷五月综合色奶水99啪| 久久久中文字幕日本| 99久久精品费精品国产| 久久久av波多野一区二区| 久久狠狠爱亚洲综合影院 | 四虎国产精品成人免费久久| 久久99国产精品成人欧美| 国产精品久久网| 国产精品美女久久久久| 久久久久亚洲精品无码蜜桃| 中文字幕久久精品无码| 久久久久久伊人高潮影院| 中文字幕亚洲综合久久菠萝蜜| 精品久久人人妻人人做精品| 色综合久久久久网| 99久久精品免费国产大片| 久久电影网一区| 久久亚洲国产欧洲精品一| 91精品国产高清久久久久久国产嫩草 | 亚洲精品97久久中文字幕无码| 久久黄色视频| 武侠古典久久婷婷狼人伊人|