Uva - 400 - Unix ls
来源:互联网 发布:linux重启后ip没有了 编辑:程序博客网 时间:2024/05/21 07:35
先计算出最长文件的长度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时补字符extravoid 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和行数rowsint 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;}
0 0
- UVa 400 - Unix ls
- uva 400 Unix ls
- UVA 400 - Unix ls
- uva 400 - Unix ls
- uva-400-Unix ls
- UVa 400 - Unix ls
- UVA 400 Unix ls
- UVa 400 - Unix ls
- uva 400 - Unix ls
- UVa - 400 - Unix ls
- uva 400 Unix ls
- UVa 400 - Unix ls
- UVa 400 - Unix ls
- UVa:400 - Unix ls
- UVa 400 - Unix ls
- UVA - 400 Unix ls
- Uva 400 Unix ls
- UVA - 400 Unix ls
- 快学Scala 第六章习题答案
- 开源框架下载
- java面试中问及Hibernate与 MyBatis的对比,在这里做一下总结
- Linux 下使用Sigar 获取CPU 使用率
- Codeforces548D:Mike and Feet(单调栈)
- Uva - 400 - Unix ls
- os.rename 和 renames方法的使用
- HTML5通过js调用手机摄像头
- 构建乘积数组
- 菜鸟学习版本管理系统 Git 和 代码托管平台 GitHub
- 移动端尺寸基础知识
- inux touch 命令 - 为什么我们需要改变时间戳?
- 浙江大学PAT_乙级_1003. 我要通过!(20)
- 根据Agent跳转到手机页面