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

            Description

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

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

            Input

            N
            N個(gè)數(shù)

            Output

            連接成的多位數(shù)

            Sample Input

            3
            13 312 343
            0

             

            Sample Output

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



            本來我也是第二種思路的,我看了感覺不像,因?yàn)橐郧皩戇^了!
            早上的幾點(diǎn)收獲:
            1、<string>頭文件和<string.h>頭文件是不一樣的!運(yùn)行時(shí)的一個(gè)錯(cuò)誤,弄了一個(gè)早上,最后發(fā)現(xiàn)這什么個(gè)問題!
            2、運(yùn)用容器,排序字符串
             
            
                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;
                }

            不過會(huì)有很多警告,讓我很苦惱!有誰知道呢?
            警告如下:
            --------------------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 閱讀(895) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Questions
            哈哈哈哈哈哈
            久久91综合国产91久久精品| 亚洲中文字幕无码久久2020| 人妻无码αv中文字幕久久 | 久久久久国产精品嫩草影院| 久久99精品国产99久久6| 久久电影网一区| 久久精品国产亚洲网站| www久久久天天com| 久久综合九色综合久99| 午夜不卡888久久| 久久久久综合中文字幕| 日韩欧美亚洲国产精品字幕久久久 | 国产午夜精品理论片久久影视| 久久久久久亚洲精品成人 | 久久精品国产亚洲av麻豆图片| 久久中文字幕人妻熟av女| 亚洲中文字幕久久精品无码喷水 | 精品999久久久久久中文字幕| 久久精品天天中文字幕人妻| 国产精品一区二区久久国产| 日韩欧美亚洲综合久久影院d3| 久久久久综合中文字幕| 亚洲综合伊人久久综合| 久久狠狠色狠狠色综合| 亚洲欧美久久久久9999| 久久久久免费看成人影片| 办公室久久精品| 东方aⅴ免费观看久久av| 久久精品国产影库免费看| 亚洲国产高清精品线久久 | 丰满少妇人妻久久久久久| 大美女久久久久久j久久| 99精品国产免费久久久久久下载| 99精品久久精品| 亚洲日本久久久午夜精品| 国产成人无码久久久精品一| 青草久久久国产线免观| 99久久国产综合精品麻豆| 久久无码国产专区精品| 国产日韩久久免费影院| 国产精品99久久精品|