UVa 400 Unix ls:字符串排序&规格化输出

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 you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to write the formatter for the ls function.

Your program will eventually read input from a pipe (although for now your program will read from the input file). Input to your program will consist of a list of (F) filenames that you will sort (ascending based on the ASCII character values) and format into (C) columns based on the length (L) of the longest filename. Filenames will be between 1 and 60 (inclusive) characters in length and will be formatted into left-justified columns. The rightmost column will be the width of the longest filename and all other columns will be the width of the longest filename plus 2. There will be as many columns as will fit in 60 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 will contain an indefinite number of lists of filenames. Each list will begin with a line containing a single integer ( ). There will then be N lines each containing one left-justified filename and the entire line's contents (between 1 and 60 characters) are considered to be 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 curly braces). There will be no illegal characters in any of the filenames and no line will be completely empty.

Immediately following the last filename will be the N for the next set or the end of file. You should read and format all sets in the input file.

Output

For each set of filenames you should print a line of exactly 60 dashes (-) followed by the formatted columns of filenames. The sorted filenames 1 to R will be listed down column 1; filenames R+1 to 2R listed down column 2; etc.

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

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索filename
, and
, Columns
, of
, The
Characters
uva400、uva11400、uva uvb uv400、unix时间戳、from unixtime,以便于您获取更多的相关知识。

时间: 2024-09-20 06:22:34

UVa 400 Unix ls:字符串排序&规格化输出的相关文章

Java字符串排序中文+数字

  思路: 在Java中,排序需要复写的是 equals 方法 和 Comparable<T> 接口 的public int compareTo(T o); 方法 步骤: 1. 使用正则表达式来判断数字,多个连续的数字作为一组, 2. 一次检索出数字组合, 3. 检出下一组数字,如果有,则进入步骤4,否则进入步骤6. 4. 如果两组数字出现的位置相等,并且前面部分的字符串相等,则进入第5步.否则break,跳到第6步. 5. 如果前面部分的字符串完全一致.则比较两个数字的大小,如果大小一致,则

java-Java中如何截取字符串数组中一段数字按大小进行排序,再输出整个排序后的字符串?

问题描述 Java中如何截取字符串数组中一段数字按大小进行排序,再输出整个排序后的字符串? String[] meg ={"1#zhang#3207237","2#Wang#3207232"...}根据最后的数字大小排序后输出 解决方案 帮助lz实现了一下,望采纳 import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.uti

字符串指针 内存非法-用指针对字符串排序的问题,内存访问非法(续)

问题描述 用指针对字符串排序的问题,内存访问非法(续) 还是上次类似的问题,求解答. 对字符串进行排序的问题,被指针搞糊涂了. #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { void sort(char p[][5]); char ss[10][5]={"worin","trafi","panda","dala

[华为机试练习题]12.整型字符串排序

题目 给定字符串内有很多正整数,要求对这些正整数进行排序,然后返回排序后指定位置的正整数 排序要求:按照每个正整数的后三位数字组成的整数进行从小到大排序 1)如果不足三位,则按照实际位数组成的整数进行比较 2)如果相等,则按照输入字符串中的原始顺序排序 说明(以下内容考生无须检查,调用者保证): 1) 字符串以'\0'结尾,仅包含数字.空格 2) 字符串内正整数之间以单个空格分隔,字符串首尾没有空格 3) 正整数格式为十进制,大小:1~1000000,正整数的数字非零开始 示例: 如字符串内容

多线程字符串排序比赛-后记

作者:野王 代码链接:https://github.com/corejava/WordSorter/blob/master/C/sort_word.cpp 节前参加了多线程字符串排序性能比赛 ,觉得挺有意思 , 也学到了一些东东,本文分享一下在参与这次比赛的过程中我对程序优化的心得. 1. 充分利用cpu 一定要充分的把cpu利用起来(多线程), 而且尽可能的不要使用锁, 锁要慎用.我的方法是让每个线程知道自己应该干什么,这样线程之间就不需要用锁来做任务协调了. 2. 排序的优化 影响排序性能的

c语言-C语言用指针给字符串排序,错在哪?

问题描述 C语言用指针给字符串排序,错在哪? #include #include void main() { void max(char *x,char *y,char *z); char a[50],b[50],c[50],d,*p,*q,*m; printf("请输入三个字符串 "); gets(a); gets(b); gets(c); p=a; q=b; m=c; printf("排序如下; "); max(p,q,m); puts(p);puts(q);p

mysql-MySQL数据库的字符串排序

问题描述 MySQL数据库的字符串排序 已经知道这种排序是因为字符串排序导致的,请问怎样解决,求大神指教 解决方案 SELECT * from dict_item where did='dict_doctorworktime' ORDER BY cast(code as SIGNED);这样应该就可以了. 解决方案二: 转换一下类型 解决方案三: 既然是数字,那就用数值类型的字段,要么就动态转换成int

C++ 用指向指针的指针的方法对5个字符串排序并输出时遇到的问题

问题描述 C++ 用指向指针的指针的方法对5个字符串排序并输出时遇到的问题 //用指向指针的指针的方法对5个字符串排序并输出 void sort(char **p) { char* temp=new char;//为什么没有长度呢?这么可以没有长度呢?? for(int j=0;j<5;j++) { for(int k=j;k<5;k++) { if(strcmp(p[j],p[k])>0) { temp=p[j]; p[j]=p[k]; p[k]=temp; } } } } int m

字符串排序

字符串排序的算法,将字符串从小到大输出 样例输入 2 2 Hello World 4 I Love C Language! 样例输出 Hello World C I Language! Love code: #include<stdio.h> #include<string.h> int main() {     int t,n;     int k,i,j,m;     char a[101][201],temp[201];     freopen("5.in"