400-unix ls
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem &problem=341
The computer company your work for are introducing a brand new computer line and is developing a new unix-like SYS TEM to is introduced along with the new computer. Your assignment is to write the formatter for the LS function.
Your program would eventually read input from a pipe (although for today Your program would read from the input file). Input to your program would consist of a list of (F) filenames that and would sort (ascending based on the ASCII character V alues) and format into (C) columns based on the length (L) of the longest filename. Filenames'll be between 1 and (inclusive) characters in length and would be formatted into left-justified columns. The rightmost column would be the width of the longest filename and all other columns'll be the width of the longest file Name plus 2. There would be as many columns as'll fit in characters. Your program should use as few rows (R) as possible with rows being filled to capacity from left to right.
Input
The input file would contain an indefinite number of lists of filenames. Each list would begin with a-line containing a single integer (). There would then be N lines each containing one left-justified filename and the entire line ' s contents (between 1 and CH Aracters) are considered to is part of the filename. allowable characters are alphanumeric (A to Z, A to Z, and 0 to 9) and from the following set {. _-} (not including the C Urly braces). There'll be no illegal characters of the filenames and no line would be completely empty.
Immediately following the last filename'll be is the N for the next set or the end of file. You are should read and format all sets in the input file.
Output
For each set of filenames your should print a line of exactly dashes (-) followed by the formatted columns of filenames. The sorted filenames 1 to R is listed down column 1; Filenames r+1 to 2R listed down column 2; etc.
Sample Input
Tiny
2short4me
very_long_file_name
shorter
size-1
size2 size3 much_longer_ Name
12345678.123
mid_size_name
weaser
alfalfa
stimey
buckwheat
Porky
Joe
Darla
Cotton
Butch Froggy mrs_crabapple
.
mr._french
Jody
Buffy
sissy
Keith
Danny
Lori
Chris
Shirley
Marsha
Cindy
Carol
Mike
Greg
Peter
Bobby
Alice
Ruben