【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

设n个字符串中出现的最长的为len;
最后一列能容纳len个字符,然后前面的列能容纳len+2个字符。
每行最多60个字符。
按照这样的排版,按照字典序,按列输出每个字符串。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 100;
const int M = 60; int n,len;
string s[N + 10 ]; void fil(int num, int used ,char key)
{
for (int i = 0; i < num-used; i++)
putchar(key);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
//ios::sync_with_stdio(0), cin.tie(0);
while (cin >> n)
{
len = 0;
for (int i = 0; i < n; i++)
{
cin >> s[i];
len = max(len, (int)s[i].size());
}
int col = (M - len) / (len + 2) + 1;
int row = (n - 1) / col + 1;
sort(s, s + n);
fil(M,0, '-'); puts("");
for (int i = 0, num; i < row; i++)
{
for (int j = 0; j < col; j++)
{
int x = j*row + i;
if (x > n - 1) break;
cout << s[x];
fil(j == col - 1 ? len : len + 2, (int)s[x].size(), ' ');
}
puts("");
}
}
return 0;
}

【例题5-8 UVA - 400】Unix ls的更多相关文章

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

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

  2. UVA 400 Unix ls by sixleaves

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

  3. Uva - 400 - Unix ls

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

  4. uva 400 Unix ls 文件输出排版 排序题

    这题的需要注意的地方就是计算行数与列数,以及输出的控制. 题目要求每一列都要有能够容纳最长文件名的空间,两列之间要留两个空格,每一行不能超过60. 简单计算下即可. 输出时我用循环输出空格来解决对齐的 ...

  5. UVa 400 Unix Is

    题意:给出n个字符串,按照字典序排列,再按照规则输出. ===学习的紫书,题目意思很清楚,求列数和行数最开始看的时候木有看懂啊啊啊 列数:即为(60-M)/(M+2)+1;即为先将最后那一列减去,算普 ...

  6. UVa - 1593 Unix ls(STL)

    给你一堆文件名,排序后按列优先的方式左对齐输出. 假设最长文件名长度是M,那么每一列都要有M+2字符,最后一列有M字符. inmanip真NB..orz #include <iostream&g ...

  7. UVa 400 Unix Is命令

    简单题 #include <bits/stdc++.h> using namespace std; const int maxn=110; string s[maxn]; int main ...

  8. UVa400.Unix ls

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

  9. UVA 400 (13.08.05)

     Unix ls  The computer company you work for is introducing a brand new computer line and is developi ...

随机推荐

  1. Razor数组数据

    控制器层 public ActionResult DemoArray() { Product[] array = { new Product {Name = "Kayak", Pr ...

  2. bash命令集---文件的操作

    git bash命令集: clear:清除窗口中的内容 ls touch cat more head tail mv cp rm diff chmod gzip gunzip gzcat lpr lp ...

  3. PHP温习之二

    1.php包含的超全局变量 (1)$GLOBALS超全局变量组,在PHP脚本所有的作用域均可以访问到. <?php $x = 23; $y = 17; function addAction(){ ...

  4. 洛谷——T1725 探险

    http://codevs.cn/problem/1725/ 时间限制: 1 s  空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解  查看运行结果   题目描述 Descri ...

  5. 2.Java实现基于SOAP的XML文档网络传输及远程过程调用(RPC)-

    转自:https://blog.csdn.net/a214919447/article/details/55260411 SOAP(Simple Object Access Protocol,简单对象 ...

  6. 团队作业-Beta冲刺(3)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cnblo ...

  7. 8 Great Java 8 Features No One's Talking about--转载

    原文地址:http://www.infoq.com/articles/Java-8-Quiet-Features If you haven’t seen some of the videos or t ...

  8. 洛谷P3954 成绩【民间数据】

    题目背景 数据已修复 题目描述 牛牛最近学习了C++入门课程,这门课程的总成绩计算方法是: 总成绩=作业成绩×20%+小测成绩×30%+期末考试成绩×50% 牛牛想知道,这门课程自己最终能得到多少分. ...

  9. 7.Linux 输入子系统分析

    为什么要引入输入子系统? 在前面我们写了一些简单的字符设备的驱动程序,我们是怎么样打开一个设备并操作的呢? 一般都是在执行应用程序时,open一个特定的设备文件,如:/dev/buttons .... ...

  10. Boost解析xml——xml写入

    <?xml version="1.0" encoding="utf-8"?> <Config> <Item name=" ...