简单数据结构-Uva400 Unix Is命令(题解、翻译及分析,参考紫书)

题目分析

本题乍看来比较复杂,其实只是一个简单的排序问题,但是输出有坑(Uva常态)。此处为了理解题意,我们做一个翻译练习,权当练一下英语(为竞赛的英语环境做准备)。

自己写的翻译

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.
你所工作的电脑公司正在推行一个全新的电脑系列(brand:系列,品牌;introduce这里是推行/推出的意思)并且正在研发一种新的Unix式的操作系统(operating system:操作系统),这些操作系统将会随着电脑一起被推出。你的任务(assignment除了有分配的意思之外,还可以理解为被安排的任务)是为Is function写一个格式化程序(formatter:格式化程序)。
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 © 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 ® as possible with rows being filled to capacity from left to right.
你的程序的最终目的是从一个管中(尽管现在你的程序将从输入文件中进行读取)进行读取【这个管很清奇啊】。你输入进去的东西将包含一系列的文件名,这些文件名需要你进行排序【这句话前面的都是废话,这里才到重点,看题时着重注意需要你做什么】(根据ASCII码进行升序排序,ascending:升序)【注意这个ascend单词很重要】,并根据最长文件名来进行列方向的安排。(format:安排,设计;格式化 column:列 就是线性代数里面常用的 r和c里面的那个c)。文件名将包括1到最多60个字母(inclusive:包容的),并进行列方向的左对齐排列(left-justified:左对齐;justify:证明;对。。。解释;调整使全行排满;使每行排齐;使齐行)。最右端列的按照最右端列上最长文件名的长度对齐就行,其它列上的则按照其它所有列的所有文件名的最长的那个来确定带宽,带宽为最长文件名长度加2(即无论其它文件名多长,都要占带宽那么大的长度,且占带宽是左对齐的)。【之前看紫书上那些只言片语一片懵逼,现在看来还是直接看英文原文更容易理解,此处为意译,事实上我们竞赛不一定非要逐字逐句地将英文转译为中文,而是看到英文能理解题目的要求就行。】列是尽可能多的,且每行最多可以包含60个字符(最多60个字符列)。你的程序需要用尽量少的行从左到右进行填充(capacity:容量)
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.

注

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值