UVA400 Unix ls
来源:互联网 发布:硕士毕业论文 知乎 编辑:程序博客网 时间:2024/05/19 03:43
字典序,直接套用的Collections.sort()进行快速排序
import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;/** * Created by 95112 on 10/20/2017. */public class Unix_ls { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); ArrayList<ArrayList<String>> answers = new ArrayList<>(); int[][] attribution = new int[10000][3]; int count = 0; while (scanner.hasNextInt()) { int n = scanner.nextInt(); if (n==0) break; ArrayList<String> storage = new ArrayList<>(); String input; int standardLength = 60; int maxSize = 0; for (int i =0 ; i < n;i++) { input = scanner.next(); if (maxSize<input.length()) maxSize = input.length(); storage.add(input); } Collections.sort(storage); int columns = (standardLength - maxSize)/(maxSize+2)+1; int rows = 0; while(rows * columns < storage.size()) ++rows; attribution[count][0] = rows; attribution[count][1] = columns; attribution[count][2] = maxSize; count++; answers.add(storage); } for (int i =0 ; i< answers.size();i++) { ArrayList<String> answer = answers.get(i); String[][] show = new String[attribution[i][0]][attribution[i][1]]; int rows = attribution[i][0]; int columns = attribution[i][1]; int maxSize = attribution[i][2]; System.out.println("------------------------------------------------------------"); for (int y =0; y < columns; y++) for (int x = 0; x < rows ; x++) { String tmp; if (x + y*rows < answer.size()) tmp = answer.get(x + y*rows); else tmp = " "; if (y != columns -1) while (tmp.length() < maxSize+2) tmp = tmp + " "; show[x][y] = tmp; } for (int x = 0 ; x < rows ; x++) { for (int y = 0 ; y < columns;y++) { System.out.print(show[x][y]); } System.out.println(""); } } }}
阅读全文
0 0
- UVa400 Unix ls
- Unix ls UVA400
- UVa400 Unix ls
- UVA400 Unix ls
- UVA400 Unix ls
- UVA400-Unix的ls命令
- uva400 unix ls (字符串 排序)
- [UVA400]Unix ls[格式输出]
- Uva400——Unix ls
- 例题5-8 Unix ls 命令 UVa400
- Uva400 Unix ls 【排序+技巧】【例5-8】
- UVA400 Unix Is
- UVa400 Unix Is
- Uva400 Unix is
- UVA400
- UVA400
- uva400
- uva400
- Screen 相关整理
- test
- 阿里云专有网络VPC使用教
- Webpack是什么(基本含义)
- 佛祖保护,代码永无bug
- UVA400 Unix ls
- jquery+表单验证(标签操作)
- PopupWindow详解
- Django实现登录
- Mac环境下配置andrion环境变量-RectNative引发的问题
- Linux常用命令(二)
- CDC::GetDeviceCaps()物理长度与屏幕像素间的转换
- 莫比乌斯函数摘录笔记
- 输出全部的希腊字母(作业)