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 (1 N 100). 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

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

排好后从左开始一列一列向下打印,前面的要最大长度加2,最后一列是最大长度,总长度不大于60

题目看错,改了一万年

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
//#define for(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
int max(int a,int b){return a>b?a:b;} void first()
{
for(int i=0;i<60;i++)
pf("-");
pf("\n");
}
int main()
{
// f reopen("output1.txt", "r", stdin);
int n;
cout.setf(std::ios::left);
while(~sf("%d",&n))
{
// getchar(); string a[105];
int Max=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
Max=max(Max,a[i].size());
}
first();
int m=(60-Max)/(Max+2)+1;//m是确定一行多少个
int sum=n/m;//sum是多少行
int ans=n%m;//ans是最后一行多少列
int i=1,time=0,temp=0;
if(ans) sum++;
sort(a,a+n);
for(int i=0;i<sum;i++)
{
for(int j=0;j<m;j++)
{
if(j*sum+i+1>n) break;
if(j==m-1)
cout<<setfill(' ')<<setw(Max)<<a[j*sum+i];
else
cout<<setfill(' ')<<setw(Max+2)<<a[j*sum+i];
}
cout<<endl;
} }
return 0;
}

F - Unix ls的更多相关文章

  1. UVa400.Unix ls

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 400 - Unix ls (Unixls命令)

    csdn : https://blog.csdn.net/su_cicada/article/details/86773007 例题5-8 Unixls命令(Unix ls,UVa400) 输入正整数 ...

  3. UVA 400 Unix ls by sixleaves

    题目其实很简单,答题意思就是从管道读取一组文件名,并且按照字典序排列,但是输入的时候按列先输出,再输出行.而且每一行最多60个字符.而每个文件名所占的宽度为最大文件名的长度加2,除了输出在最右边的文件 ...

  4. unix ls命令

    [语法]: ls  [-RadCxmlnogrtucpFbqisf1]   [文件夹或文件......] [说明]: ls 命令列出指定文件夹下的文件,缺省文件夹为当前文件夹 ./,缺省输出顺序为纵向 ...

  5. Unix - ls命令的简要实现

    #include <dirent.h> 是POSIX.1标准定义的unix类目录操作的头文件,包含了许多UNIX系统服务的函数原型,例如opendir函数.readdir函数. opend ...

  6. Unix ls UVA - 400

      The computer company you work for is introducing a brand new computer line and is developing a new ...

  7. 【例题5-8 UVA - 400】Unix ls

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设n个字符串中出现的最长的为len; 最后一列能容纳len个字符,然后前面的列能容纳len+2个字符. 每行最多60个字符. 按照这 ...

  8. UVa 400 (水题) Unix ls

    题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个 ...

  9. Uva - 400 - Unix ls

    先计算出最长文件的长度M,然后计算列数和行数,最后输出即可. AC代码: #include <iostream> #include <cstdio> #include < ...

随机推荐

  1. 版本控制-GitHub

    前面几篇文章,我们介绍了Git的基本用法及Git服务器的搭建,本篇文章来学习一下如何使用GitHub.GitHub是开源的代码库以及版本控制库,是目前使用网络上使用最为广泛的服务,GitHub可以托管 ...

  2. 解决Gerrit的git unpack error问题

    今天上午同事和我说neutron项目要换成全新的内部代码,原先仓库里的代码要全部废弃掉.于是我就简单地创建了一个空项目使用git push --force将其置空. 下午的时候,麻烦事情就来了,同事发 ...

  3. 熬之滴水成石:最想深入了解的内容--windows内核机制(6)

    58 进程和线程(3) 说完进程再说说线程,线程相比于进程其实有更多可说的内容.首先实现线程调用的数据结构是个栈,该栈记录了调用方法的信息这里面也包括了函数调用及返回的地址.线程肯定是属于某个进程,其 ...

  4. MDX Cookbook 03 - MDX 查询中负数,零和空值 NULL 的格式化处理

    FORMAT_STRING 属性在处理计算成员(通常是度量值成员)的时候会经常使用到,比如指定标准 Standard, 货币 Currency 或者 Percent 百分比格式.除此之外,还可以自定义 ...

  5. Python实现doc转化pdf

    Python实现doc转化pdf python源码实现doc转化pdf #-*- coding:utf-8 -*- # doc2pdf.py: python script to convert doc ...

  6. 周期同步位置模式(CSP),轮廓位置模式(PPM),位置模式(PM)

    什么是运动控制? 运动控制就是通过机械传动装置对运动部件的位置.速度进行实时的控制管理,使运动部件按照预期的轨迹和规定的运动参数(如速度.加速度参数等)完成相应的动作. 运动控制系统的典型构成 1. ...

  7. 谈谈MySQL死锁 一

    数据越来越和我们的生活离不开,数据在生命周期的各个阶段有着不同的痛点和需求以及特殊场景. CURD是数据的四大基本需求:写入,更新,读取,删除. 今天,来谈一谈死锁问题 死锁是高并发下MySQL不可回 ...

  8. ant+svn+tomcat实现自动构建

    前段时间用做了一个简单的web api服务,在调试的过程中感觉到手动发布实在是效率低而且容易出错,于是花点时间搞了一下ant+svn+tomcat的自动构建,效果不错,今天拿出来分享一下. 准备工作 ...

  9. IDEA使用笔记(七)——编辑器最大个数的设置

    我想一定有许多人和我一样在使用IDEA的时候,打开了许多的编辑器选项卡,但是打开的数量是有限的,我们想打开更多的页面,并且希望控制当再次达到大限的时候能关闭那些我们最久没有看的文件! 好吧!看下面的配 ...

  10. 学习笔记 07 --- JUC集合

    学习笔记 07 --- JUC集合 在讲JUC集合之前我们先总结一下Java的集合框架,主要包含Collection集合和Map类.Collection集合又能够划分为LIst和Set. 1. Lis ...