我是靠谱客的博主 碧蓝衬衫,这篇文章主要介绍Uva 400 - Unix ls,现在分享给大家,希望可以做个参考。

题意: 给出几个字符串,按给定格式输出。
简单题,

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h> using namespace std; #define maxn 105 struct str { char s[100]; int slen; }data[maxn]; int n; int cmp(str a,str b) { int flag = strcmp(a.s,b.s); return flag < 0; } int main() { // freopen("D://in.txt","r",stdin); while(~scanf("%d",&n)) { memset(data,0,sizeof(data)); int maxs = 0; for(int i = 0; i < n ; i++) { scanf("%s",data[i].s); int slen = strlen(data[i].s); maxs = max(maxs,slen); data[i].slen = slen; } maxs = maxs+2; sort(data,data+n,cmp); int col = 60/maxs; if(col == 0) col++; int row = n/col; if(n%col) row++; printf("------------------------------------------------------------n"); /*for(int i = 0; i < n; i++) cout<<data[i].s<<endl;*/ //cout<<row<<' '<<col<<endl; for(int i = 0; i < row; i++) { for(int j = 0; j < col-1; j++) { int id = j*row+i; printf("%s",data[id].s); for(int k = 0; k < maxs-data[id].slen; k++) cout<<' '; } int id = (col-1)*row+i; printf("%s",data[id].s); for(int k = 0; k < maxs-2-data[id].slen; k++) cout<<' '; cout<<endl; } } return 0; }

最后

以上就是碧蓝衬衫最近收集整理的关于Uva 400 - Unix ls的全部内容,更多相关Uva内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部