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

【题意】

在这里输入题意

【题解】

设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. python-openpyxl安装

    今天在安装openpyxl的时候,一直提示错误,后来才发现仅仅安装它还不够,还需要其他两个库的支持1.安装jdcal2.安装et_xmlfile这两个库安装的方法,都是直接在命令行下面,进入库文件se ...

  2. HDU 3594 The trouble of Xiaoqian 混合背包问题

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  3. Python day4知识回顾

    # -*- coding: utf_8 _*_# Author:Vi#字典是无序的 info = { 'student001':"DIO", 'student002':" ...

  4. C# WinForm设置透明

    1:通过设置窗体的 TransparencyKey实现  例:窗体中的白色会变成透明      this.BackColor =Color.White; this.TransparencyKey = ...

  5. c# winform 技术提升

    http://www.cnblogs.com/junjie94wan/category/303961.html http://www.cnblogs.com/springyangwc/archive/ ...

  6. 移动GPU全解读(二)

    [编者按]:本文作者为爱搞机特约作者.技术达人"炮神"@ioncannon. 在上一篇移动GPU解读中,对移动GPU的架构.相关參数进行了介绍,本部分介绍的则是移动GPU的Shad ...

  7. 【MongoDB】mongodump and mongorestore of mogodb

    The another tool will be mentioned in this blog, namely mongodump and mongorestore. General speaking ...

  8. 摆脱技术思维,转向产品思维——寻找“万能”IDC的苦恼

    背景:近期在新产品的开发任务完毕后一直在为寻找好的IDC和优质的托管服务忙碌.需求源自于我们重点要解决之前老版产品面临的国内外用户訪问速度慢甚至连接不上的问题. 除去架构技术上使用高性能.可扩展的方案 ...

  9. 20.Node.js EventEmitter的方法和事件

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html EventEmitter 提供了多个属性,如 on 和 emit.on 函数用于绑定事件函数, ...

  10. 读阮一峰《ECMAScript 6 入门》小结

    读阮一峰<ECMAScript 6 入门>小结,http://es6.ruanyifeng.com/ 1. ES6简介 Babel 是一个广泛使用的 ES6 转码器,可以将 ES6 代码转 ...