Uva400——Unix ls
2015-10-29 23:02
288 查看
#include <iostream> #include <string> #include <algorithm> using namespace std; string name[105]; const int maxcol = 60; int max(int x, int y) { return x > y ? x : y; } void print(const string &s, int len, char extra) { cout << s; for(int i = 0; i < len - s.length(); i++) cout << extra; } int main() { // freopen("400.txt", "r", stdin); int n; while(cin >> n) { int M = 0; for(int i = 0; i < n; i++) { cin >> name[i]; M = max(M, (int)name[i].length()); } int cols = (maxcol - M) / (M + 2) + 1; int rows = (n - 1) / cols + 1; print("", 60, '-'); cout << endl; sort(name, name + n); for(int r = 0; r < rows; r++) { for(int c = 0; c < cols; c++) { int idx = c * rows + r; if(idx < n) print(name[idx], c == cols - 1 ? M : M + 2, ' '); } cout << endl; } } return 0; }
相关文章推荐
- 如何在github上传自己的项目
- 十天冲刺---Day1
- Java String API
- Java String API
- 欢迎使用CSDN-markdown编辑器
- 关于修改 commit_write 提升性能的一点理解
- 记。。关于python处理表单
- C语言文法
- LeetCode Unique Paths (简单DP)
- LeetCode 刷题: 两个二叉树节点的最近公共节点Least Common Ancestor
- 1.6-nagios监控客户端-2
- 关注博客:夏冰加密软件技术博客(加密相关技术博客)
- java.lang.RuntimeException: java.lang.NullPointerException...的错误
- AngularJs angular.identity和angular.noop
- 不可不知的前端
- Elasticsearch分组聚合-查询每个A_logtype下有多少数据
- jQuery实现点击弹出层3秒后自动消失
- 更改 状态栏(UIStatusBar)的颜色
- ajax入门详解
- Media and Camera 中 Camera 模块