我是靠谱客的博主 刻苦台灯,这篇文章主要介绍UVA 400-Unix ls【字符串】,现在分享给大家,希望可以做个参考。

原题网址:


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=341




按要求进行排版.....左对齐,不够的补空格............



复制代码
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
#include<stdio.h> #include<iostream> #include<string.h> #include<string> #include<algorithm> using namespace std; int main() { int n,col=60; //freopen("shuju.txt","r",stdin); while(~scanf("%d",&n)) { string s[105]; int M=0; for(int i=0;i<n;++i) { //scanf("%s",tp); cin >> s[i]; M=max(M,(int)s[i].length());//找最大长度 } int y=(col-M)/(M+2)+1,x=(n-1)/y+1; //注意计算 x 是行 y 是列 printf("------------------------------------------------------------n"); sort(s,s+n); for(int i=0;i<x;++i) { for(int j=0;j<y;++j) { int site=i+j*x,size=M,k=s[site].length(); if(j<x-1) { size+=2; } char tp[1005];tp[k]=0; cout << s[site]; while(k++<=size) { printf(" "); } } printf("n"); } } return 0; }


不得不学习一点关于string 类型的东西了............

学吧!





最后

以上就是刻苦台灯最近收集整理的关于UVA 400-Unix ls【字符串】的全部内容,更多相关UVA内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部