• <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>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0

            題目要求模擬Unix下ls命令。給出一些列文件名,按字典序排序之后,以列優(yōu)先的方式輸出。除了最后一列之外,其余各列所占的字符數(shù)為最長文件名長度加2,最后一列所占數(shù)目為最長文件名長度。每行字符數(shù)不能超過60,要求最終的行數(shù)最少。
            WA了2次,實在不應(yīng)該,列輸出方式?jīng)]有控制好。我的做法是先輸出到二維string數(shù)組中,因為這個數(shù)組并不一定被填滿,這樣一來接下來輸出時有多種選擇:1、做標記,沒有被標記的元素不用輸出(我最初這一步?jīng)]有做好);2、判斷(i,j)對應(yīng)的文件名數(shù)組中的位置是否越界(不占用額外空間,不用對二維string數(shù)組賦值)。
            以下是我的代碼:

            #include<iostream>
            #include
            <string>
            #include
            <algorithm>
            #include
            <cstdio>
            using namespace std;
            const int kMaxn(107);

            string r[kMaxn],ls[kMaxn][kMaxn];

            int main()
            {
                
            /*
                freopen("data.in","r",stdin);
                freopen("data.out","w",stdout);
                //
            */

                
            int n;
                
            while(cin>>n)
                {
                    
            int max_length(0);
                    
            for(int i=1;i<=n;i++)
                    {
                        cin
            >>r[i];
                        max_length
            =max(max_length,static_cast<int>(r[i].size()));
                    }

                    sort(r
            +1,r+n+1);
                    
            int row_num,column_num;
                    
            for(row_num=1;row_num<=n;row_num++)
                    {
                        column_num
            =n/row_num;
                        
            if(n%row_num)
                            column_num
            ++;
                        
            if((max_length+2)*(column_num-1)+max_length<=60)
                            
            break;
                    }
                    
            for(int i=1,x=1,y=1;i<=n;i++)
                    {
                        ls[x][y]
            =r[i];
                        x
            ++;
                        
            if(x>row_num)
                        {
                            x
            =1;
                            y
            ++;
                        }
                    }

                    
            for(int i=1;i<=60;i++)
                        cout
            <<"-";
                    cout
            <<endl;
                    
            for(int i=1;i<=row_num;i++)
                    {
                        
            for(int j=1;j<=column_num;j++)
                        {
                            
            if((j-1)*row_num+i<=n)
                            {
                                cout
            <<ls[i][j];
                                
            for(int k=ls[i][j].size();k<(j==column_num?max_length:(max_length+2));k++)
                                    cout
            <<" ";
                            }
                        }
                        cout
            <<endl;
                    }
                }

                
            return 0;
            }
            posted on 2011-04-09 17:24 lee1r 閱讀(1200) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:字符串處理題目分類:排序
            青青热久久综合网伊人| 国产成人综合久久精品红| 国产欧美久久一区二区| 亚洲狠狠久久综合一区77777 | 亚洲?V乱码久久精品蜜桃| 久久久久亚洲AV成人网人人网站 | 久久996热精品xxxx| 久久人人爽人人爽人人av东京热 | 午夜福利91久久福利| 亚洲AV无码1区2区久久 | 无码人妻久久一区二区三区免费| 97超级碰碰碰久久久久| 亚洲精品第一综合99久久| 久久免费国产精品一区二区| 久久中文字幕人妻丝袜| 久久国产精品免费| 久久精品成人免费网站| 亚洲∧v久久久无码精品| 久久久精品国产Sm最大网站| 成人国内精品久久久久一区| 2019久久久高清456| 久久精品夜色噜噜亚洲A∨| 久久精品男人影院| 久久精品欧美日韩精品| 久久精品人妻中文系列| 久久影视国产亚洲| 香蕉久久永久视频| 久久综合亚洲色HEZYO国产| 国产精品成人无码久久久久久 | 色偷偷88欧美精品久久久| 精品久久久无码中文字幕| 国产精品美女久久久久AV福利| 久久精品国产99久久久| 久久国产精品77777| 国产精品99精品久久免费| 久久婷婷激情综合色综合俺也去| 久久久久久精品无码人妻| 久久国产免费直播| 丰满少妇高潮惨叫久久久| 91久久九九无码成人网站| 久久精品国产国产精品四凭|