• <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 閱讀(904) 評論(0)  編輯 收藏 引用 所屬分類: Questions
            哈哈哈哈哈哈
            精品久久久久久中文字幕大豆网| 日日狠狠久久偷偷色综合0| 久久91精品久久91综合| 久久国产高清一区二区三区| 亚洲精品高清一二区久久| 久久久亚洲欧洲日产国码aⅴ| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产精品99久久精品爆乳| 美女久久久久久| 精品久久久久久久无码| 一本久久精品一区二区| 亚洲国产天堂久久综合网站 | 久久国产精品一国产精品金尊| 久久av高潮av无码av喷吹| 久久精品国产亚洲AV电影| 亚洲美日韩Av中文字幕无码久久久妻妇| 97久久精品无码一区二区天美| 久久精品桃花综合| 久久精品中文字幕第23页| 久久―日本道色综合久久| 性色欲网站人妻丰满中文久久不卡| 久久线看观看精品香蕉国产| 久久久久亚洲AV成人网人人网站| 久久精品国产只有精品66| 99久久精品午夜一区二区| 伊人久久综合成人网| 性做久久久久久免费观看| segui久久国产精品| 麻豆亚洲AV永久无码精品久久| 久久久这里有精品中文字幕| 久久久无码精品午夜| 一本色综合久久| 久久只有这里有精品4| 国产精品99久久久精品无码| 亚洲а∨天堂久久精品9966| 亚洲欧美精品一区久久中文字幕| 四虎国产精品免费久久| A级毛片无码久久精品免费| 亚洲综合伊人久久大杳蕉| 久久久久久九九99精品| 精品国产福利久久久|