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 ...
随机推荐
- DCOM EXCE权限配置问题
检索COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005: 关于以上这个问题,博主在百度上 ...
- Linux的哲学思想
1.一切皆文件:2.单一目的的小程序:3.组合小程序完成复杂任务:4.文本文件保存配置信息:5.尽量避免捕获用户接口:6.提供机制,而非策略. 说到底Linux的哲学思想在于方便和更好的管理后台,不同 ...
- [ SSH框架 ] Hibernate框架学习之二
一.Hibernate持久化类的编写规范 1.什么是持久化类 Hibernate是持久层的ORM影射框架,专注于数据的持久化工作.所谓持久化,就是将内存中的数据永久存储到关系型数据库中.那么知道了什么 ...
- CRM客户关系管理系统(二)
第三章.前端页面设计 3.1.前端页面布局 Bootstrap模板下载 (1)静态文件 新建statics目录(存放css/fonts/imgs/js/plugins) settings配置 STA ...
- 开源Spring解决方案--lm.solution
Github 项目地址: https://github.com/liumeng0403/lm.solution 一.说明 1.本项目未按java项目传统命名方式命名项目名,包名 如:org.xxxx. ...
- 硬盘存储计量单位KB、MB、GB大小换算
一. 预备知识 1. bit与byte 1. bit(简记为 b) 1 bit = 0 or 1 = one binary 2. byte(简记为 B) 1 byte = 8 bits 1字节,8个二 ...
- 学习笔记:Zookeeper选举机制
1.Zookeeper选举机制 Zookeeper虽然在配置文件中并没有指定master和slave 但是,zookeeper工作时,是有一个节点为leader,其他则为follower Leader ...
- Rails里rake db:migrate出现undefined method last_comment问题的解决
这个问题和特定的rake版本有关,因为Rails要使用rake的last_comment方法在较新版本的rake中已被废弃,所以很多人卸载了新版本的rake去安装旧版本的rake. 这样也能解决问题, ...
- 【SSH系列】深入浅出spring IOC中三种依赖注入方式
spring的核心思想是IOC和AOP,IOC-控制反转,是一个重要的面向对象编程的法则来消减计算机程序的耦合问题,控制反转一般分为两种类型,依赖注入和依赖查找,依赖什么?为什么需要依赖?注入什么?控 ...
- Unity 资源管理插件
之所以写这个插件呢,就是为了方便整理项目中的资源文件,我记得之前好像也用了这么一个插件,但是也没去找,还是自己动手写一个吧,需要什么功能就看自己的需求. 在项目的过程中呢,已经写了一个插件来管理材质, ...