• <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>
            voip
            風的方向
            厚德致遠,博學敦行!
            posts - 52,comments - 21,trackbacks - 0
                     苦惱啊!

            Description

            設有n個正整數,將他們連接成一排,組成一個最大的多位整數。例如:n=3時,3個整數13,312,343,連成的最大整數為:34331213

            又如:n=4時,4個整數7,13,4,246連接成的最大整數為7424613

            Input

            N
            N個數

            Output

            連接成的多位數

            Sample Input

            3
            13 312 343
            0

             

            Sample Output

            34331213
                  這個題目意思應該很好理解,至少會想有兩種解題思路,
                     一、把數組從大到小排列,這樣是最大嗎?  顯然不是,例如:123 9,應該輸出9123;
                     二、把數組按字符串排序,這樣是最大嗎?這問題可能會然我們困惑,但是這也是錯的,例如:120,12;應該輸出12120;
            這個題目不知道毒害了多少人(當然我指的是ACM新人),尤其是第二種思路去寫代碼的。。這只是一個悲劇的開始,你把一條彎路在直走!
            其實這個題目應該是屬于動態規劃的最簡單應用!子問題,給你兩個數,讓你連成最大數,一定非常簡單,只能組成兩個數,比較一下大小就成!這就是解題思路!
            如果給你三個數呢?一直遞推下去!悲劇啊,盡然怎么簡單!
            代碼如下:


            #include
            <stdio.h>
            #include
            <string.h>
            #include
            <stdlib.h>

            int main()
            {
                
            int n,i,j,l,k;
                
            char s[1000][100];
                
            char s1[200],s2[200];
                
            while(scanf("%d",&n)!=EOF&&n!=0)
                
            {
                    
            for(i=0;i<n;i++)
                    
            {
                        scanf(
            "%s",s[i]);
                        
            while(s[i][0]=='0')
                        
            {
                            
            if(strlen(s[i])==1)
                                
            break;
                            strcpy(s[i],s[i]
            +1);
                        }

                    }

                    
            for(i=0;i<n;i++)
                    
            {            
                        
            for(j=i+1;j<n;j++)
                        
            {
                            strcpy(s1,s[i]);
                            strcat(s1,s[j]);
                            strcpy(s2,s[j]);
                            strcat(s2,s[i]);
                            
            if(strcmp(s1,s2)<0)
                            
            {
                                strcpy(s1,s[i]);
                                strcpy(s[i],s[j]);
                                strcpy(s[j],s1);
                            }

                        }

                    }

                    
            for(i=0;i<n;i++)
                    
            {
                        
            if(s[0][0]=='0')
                        
            {
                            printf(
            "0");
                            
            break;
                        }

                        
            else
                        
            {
                            printf(
            "%s",s[i]);
                        }

                    }

                    printf(
            "\n");
                }

                
            return 0;
            }



            本來我也是第二種思路的,我看了感覺不像,因為以前寫過了!
            早上的幾點收獲:
            1、<string>頭文件和<string.h>頭文件是不一樣的!運行時的一個錯誤,弄了一個早上,最后發現這什么個問題!
            2、運用容器,排序字符串
             
            
                vector<string> words;
                
            string str;
                
            while(scanf("%s",str)!=EOF)  
                    words.push_back(str);

                sort(words.begin(),words.end(),greater
            <string>());


                
            for(vector<string>::size_type i=0;i<words.size();i++)
                
            {
                        cout
            <<words[i]<<endl;
                }

            不過會有很多警告,讓我很苦惱!有誰知道呢?
            警告如下:
            --------------------Configuration: rongqi - Win32 Debug--------------------
            Compiling
            rongqi.cpp
            c:\documents and settings\administrator\桌面\rongqi\rongqi.cpp(
            81) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char
            > >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
            c:\documents and settings\administrator\桌面\rongqi\rongqi.cpp(81) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,st
            d::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
            c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
             >::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
            c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
             >::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information

            rongqi.obj 
            - 0 error(s), 0 warning(s)
            3、在程序頭上寫#pragma   warning  (disable:   4786),可以注銷4786以后警告!
            posted on 2010-09-06 11:52 jince 閱讀(889) 評論(0)  編輯 收藏 引用 所屬分類: Questions
            哈哈哈哈哈哈
            亚洲天堂久久精品| 理论片午午伦夜理片久久| 久久久精品国产免大香伊 | 久久精品成人欧美大片| 国産精品久久久久久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 老男人久久青草av高清| 久久久久亚洲av无码专区喷水| 久久99精品国产麻豆| 亚洲精品tv久久久久| 99精品久久精品| 精品人妻伦九区久久AAA片69| 国产精品免费看久久久香蕉| 日韩精品久久久久久免费| 久久精品视频91| 久久伊人精品青青草原高清| 久久精品国产日本波多野结衣| 久久久中文字幕| 性高湖久久久久久久久| 精品久久久一二三区| 国产免费久久精品丫丫| 久久精品国产精品亚洲毛片 | 亚洲国产精品久久久久网站 | 国产成人精品白浆久久69| 亚洲国产成人久久精品99| 久久国产美女免费观看精品| 国产亚洲精久久久久久无码| 国产激情久久久久久熟女老人| 亚洲另类欧美综合久久图片区| 国产91久久精品一区二区| 亚洲国产精品无码久久SM| 久久久午夜精品福利内容| 国产成人精品久久亚洲高清不卡 | 国产精品禁18久久久夂久| 国产成人久久精品一区二区三区 | 久久久久久一区国产精品| 一本伊大人香蕉久久网手机| 青青草国产精品久久久久| 伊人久久综在合线亚洲2019| 一本大道久久a久久精品综合| 狠狠色丁香婷婷综合久久来来去|