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

            Description

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

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

            Input

            N
            N個數(shù)

            Output

            連接成的多位數(shù)

            Sample Input

            3
            13 312 343
            0

             

            Sample Output

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


            #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>頭文件是不一樣的!運行時的一個錯誤,弄了一個早上,最后發(fā)現(xiàn)這什么個問題!
            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免费观看| 亚洲国产精品无码久久SM| 久久精品青青草原伊人| 久久久久国产精品| 久久福利青草精品资源站| 7777精品久久久大香线蕉| 伊人久久一区二区三区无码| 韩国免费A级毛片久久| 久久婷婷是五月综合色狠狠| 中文无码久久精品| 久久精品国产精品亚洲下载| 亚洲国产成人久久精品影视| 久久夜色精品国产亚洲| 久久综合九色综合97_久久久| 色综合久久天天综合| 久久国产综合精品五月天| 久久亚洲2019中文字幕| 亚洲国产日韩欧美综合久久| 99久久99久久精品国产片果冻| 亚洲国产另类久久久精品| 国产精品久久久久…| 久久久无码精品午夜| 嫩草伊人久久精品少妇AV| 精品久久久久久无码中文字幕| 99久久做夜夜爱天天做精品| 久久天天躁狠狠躁夜夜网站| 久久精品国产黑森林| 色综合久久中文字幕无码| 成人a毛片久久免费播放| 亚洲精品第一综合99久久| 99久久中文字幕| 久久久久久精品免费看SSS| 99久久99久久久精品齐齐| 亚洲国产天堂久久综合| 韩国无遮挡三级久久| 一本一本久久A久久综合精品| 中文精品久久久久国产网址| 久久精品一本到99热免费| 亚洲Av无码国产情品久久|