Uva - 400 - Unix ls
先计算出最长文件的长度M,然后计算列数和行数,最后输出即可。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
const int maxcol = 60;
const int maxn = 105;
string filenames[maxn];
// 输出函数,s长度不足len时补字符extra
void print(const string s, int len, char extra)
{
cout << s;
for (int i = 0; i < len - s.length(); i++) {
cout << extra;
}
}
int main()
{
ios::sync_with_stdio(false);
int n;
while (cin >> n) {
int M = 0; // 输出的列数
for (int i = 0; i < n; i++) {
cin >> filenames[i];
M = max(M, (int)filenames[i].length());
}
//计算列数cols和行数rows
int cols = (maxcol - M) / (M + 2) + 1;
int rows = (n - 1) / cols + 1;
print("", 60, '-');
cout << endl;
sort(filenames, filenames + n);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
int idx = c * rows + r;
if (idx < n) {
print(filenames[idx], c == cols - 1 ? M : M + 2, ' ');
}
}
cout << endl;
}
}
return 0;
}
Uva - 400 - Unix ls的更多相关文章
- UVA 400 - Unix ls (Unixls命令)
csdn : https://blog.csdn.net/su_cicada/article/details/86773007 例题5-8 Unixls命令(Unix ls,UVa400) 输入正整数 ...
- UVA 400 Unix ls by sixleaves
题目其实很简单,答题意思就是从管道读取一组文件名,并且按照字典序排列,但是输入的时候按列先输出,再输出行.而且每一行最多60个字符.而每个文件名所占的宽度为最大文件名的长度加2,除了输出在最右边的文件 ...
- uva 400 Unix ls 文件输出排版 排序题
这题的需要注意的地方就是计算行数与列数,以及输出的控制. 题目要求每一列都要有能够容纳最长文件名的空间,两列之间要留两个空格,每一行不能超过60. 简单计算下即可. 输出时我用循环输出空格来解决对齐的 ...
- UVa 400 Unix Is
题意:给出n个字符串,按照字典序排列,再按照规则输出. ===学习的紫书,题目意思很清楚,求列数和行数最开始看的时候木有看懂啊啊啊 列数:即为(60-M)/(M+2)+1;即为先将最后那一列减去,算普 ...
- UVa - 1593 Unix ls(STL)
给你一堆文件名,排序后按列优先的方式左对齐输出. 假设最长文件名长度是M,那么每一列都要有M+2字符,最后一列有M字符. inmanip真NB..orz #include <iostream&g ...
- UVa 400 Unix Is命令
简单题 #include <bits/stdc++.h> using namespace std; const int maxn=110; string s[maxn]; int main ...
- UVa400.Unix ls
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 400 (13.08.05)
Unix ls The computer company you work for is introducing a brand new computer line and is developi ...
- Unix ls UVA - 400
The computer company you work for is introducing a brand new computer line and is developing a new ...
随机推荐
- 数组查找算法的C语言 实现-----线性查找和二分查找
线性查找 Linear Search 用户输入学生学号的成绩 二分查找 Binary Search 要求数据表是已经排好序的 程序存在小的瑕疵
- 跨域资源共享CORS与JSONP
同源策略限制: 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果没有同源策略,攻击者可以通过JavaScript获取你的邮件以及其他敏感信息,比如说 ...
- WPF 窗口居中 & 变更触发机制
窗口居中 & 变更触发机制 解决: 1.单实例窗口,窗口每次隐藏后再显示时,位置居中显示 2.多屏幕下单实例窗口,当父窗口移动到其它屏幕时,单实例窗口再次弹出时,位置才更新到父窗口屏幕. 3. ...
- 迭代器&生成器
迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退 ...
- opencv视屏流嵌入wxpython框架
前几篇博客分享搭建人脸识别与情绪判断的环境和源码,但是没有UI,界面很难看,一打开就是opencv弹出的一个视屏框.处女座的我看着非常难受,于是决定做一个UI,稍微规矩好看一点,再怎么说,这样的话也算 ...
- 牛客网编程练习之PAT乙级(Basic Level):1032 选大王
典型的约瑟夫环问题 AC代码: import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * @ ...
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
错误描述为: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with ...
- ROS机器人程序设计(原书第2版)补充资料 kinetic
Effective Robotics Programming with ROS Third Edition Find out everything you need to know to build ...
- 建立自己的git服务器
需求情景 就像金山快盘同步盘那样, 在开发环境windows 10和部署环境Ubuntu server 14.04之间建立同步关系.比如windows端多了一个a.txt文件,你推送后,Ubuntu端 ...
- Git之(一)Git是什么
为什么使用Git 孔子曾经曰过的,名正则言顺 言顺则事成. 我们在学习一项新技术之前,弄清楚为什么要学它至关重要,至于为什么要学习Git,我用一段if-else语句告诉你原因: if(你相信我){ 我 ...