zoukankan      html  css  js  c++  java
  • UVa 400 -- Unix ls

     UVa 400 -- Unix ls

    Sample Input

    10
    tiny
    2short4me
    very_long_file_name
    shorter
    size-1
    size2
    size3
    much_longer_name
    12345678.123
    mid_size_name
    12
    Weaser
    Alfalfa
    Stimey
    Buckwheat
    Porky
    Joe
    Darla
    Cotton
    Butch
    Froggy
    Mrs_Crabapple
    P.D.
    19
    Mr._French
    Jody
    Buffy
    Sissy
    Keith
    Danny
    Lori
    Chris
    Shirley
    Marsha
    Jan
    Cindy
    Carol
    Mike
    Greg
    Peter
    Bobby
    Alice
    Ruben

    Sample Output

    ------------------------------------------------------------
    12345678.123         size-1               
    2short4me            size2                
    mid_size_name        size3                
    much_longer_name     tiny                 
    shorter              very_long_file_name  
    ------------------------------------------------------------
    Alfalfa        Cotton         Joe            Porky          
    Buckwheat      Darla          Mrs_Crabapple  Stimey         
    Butch          Froggy         P.D.           Weaser         
    ------------------------------------------------------------
    Alice       Chris       Jan         Marsha      Ruben       
    Bobby       Cindy       Jody        Mike        Shirley     
    Buffy       Danny       Keith       Mr._French  Sissy       
    Carol       Greg        Lori        Peter

     1 #include<iostream>
     2 #include<string>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 const int maxcol = 60;
     7 const int maxn = 100 + 5;
     8 string filenames[maxn];
     9 
    10 void print(const string& s,int len,char extra)
    11 {
    12     cout<<s;
    13     for(int i=s.length()+1;i<=len;i++)
    14     {
    15         cout<<extra;
    16     }
    17 }
    18 
    19 int main()
    20 {
    21     int n;
    22     while(cin>>n)
    23     {
    24         int M = 0;
    25         for(int i = 0;i<n;i++)
    26         {
    27             cin>>filenames[i];
    28             M = max(M,(int)filenames[i].length());
    29         }
    30         ///计算行数和列数
    31         int col = (maxcol-M)/(M+2)+1;
    32         int row = (n-1)/col + 1;
    33 
    34         sort(filenames,filenames+n);//排序
    35 
    36         print("-",60,'-');
    37         cout<<endl;
    38         for(int i=0;i<row;i++)
    39         {
    40             for(int j=0;j<col;j++)
    41             {
    42                 if((j*row+i)>=n) break;
    43                 if(j == col-1) print(filenames[j*row+i],M,' ');
    44                 else print(filenames[j*row+i],M+2,' ');
    45             }
    46             cout<<endl;
    47         }
    48 
    49 
    50     }
    51     return 0;
    
    
    
    结果:
    10
    tiny
    2short4me
    very_long_file_name
    shorter
    size-1
    size2
    size3
    much_longer_name
    12345678.123
    mid_size_name
    ------------------------------------------------------------
    12345678.123         size-1
    2short4me            size2
    mid_size_name        size3
    much_longer_name     tiny
    shorter              very_long_file_name
    12
    Weaser
    Alfalfa
    Stimey
    Buckwheat
    Porky
    Joe
    Darla
    Cotton
    Butch
    Froggy
    Mrs_Crabapple
    P.D.
    ------------------------------------------------------------
    Alfalfa        Cotton         Joe            Porky
    Buckwheat      Darla          Mrs_Crabapple  Stimey
    Butch          Froggy         P.D.           Weaser
    19
    Mr._French
    Jody
    Buffy
    Sissy
    Keith
    Danny
    Lori
    Chris
    Shirley
    Marsha
    Jan
    Cindy
    Carol
    Mike
    Greg
    Peter
    Bobby
    Alice
    Ruben
    ------------------------------------------------------------
    Alice       Chris       Jan         Marsha      Ruben
    Bobby       Cindy       Jody        Mike        Shirley
    Buffy       Danny       Keith       Mr._French  Sissy
    Carol       Greg        Lori        Peter
     
  • 相关阅读:
    firstresponder 后,键盘不显示
    performSelector
    setNeedsDisplay、setNeedsLayout 区别
    Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
    GCD介绍(一):基本概念和dispatch queues
    一些概念
    /mnt/sdcard /sdcard
    eclipse 导入已存在的工程文件出错
    ios 常用技巧
    ios nsstring去掉换行符
  • 原文地址:https://www.cnblogs.com/yxh-amysear/p/8428263.html
Copyright © 2011-2022 走看看