UVa 400 (water problem) Unix ls

Source: Internet
Author: User

Test instructions

There are n filenames, sorted by column precedence, left-aligned output. The longest file name is the length of M, the last column is M, and the other column length is m+2.

Analysis:

The problem is very simple, but to write the code to refine, still need to think about it. LRJ code has two highlights, one is the print sub-function, and the other is the calculation of the number of rows. Experience with your heart

1#include <iostream>2#include <cstdio>3#include <string>4#include <algorithm>5 using namespacestd;6 7 Const intMAXL = -;8 Const intMAXN = -+5;9 stringNAMES[MAXN];Ten  One voidPrintConst string& S,intLenCharextra) A { -printf"%s", S.c_str ()); -      for(inti = S.length (); i < Len; ++i) Putchar (extra); the } -  - intMain () - { +     //freopen ("In.txt", "R", stdin); -     intN; +      while(SCANF ("%d", &n) = =1) A     { at         intM =0; -          for(inti =0; I < n; ++i) -         { -CIN >>Names[i]; -m = max (M, (int) names[i].length ()); -         } inSort (names, names +n); -         intcols = (maxl-m)/(M +2) +1, rows = (N-1)/cols +1; toPrint"", -,'-'); +Puts""); -          for(intR =0; R < rows; ++R) the         { *              for(intc =0; c < cols; ++c) $             {Panax Notoginseng                 intindex = c * rows +R; -                 if(Index < N) print (Names[index], c = = cols-1? m:m+2,' '); the             } +Puts""); A         } the     } +  -     return 0; $}
code June

UVa 400 (water problem) Unix ls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.