首页 > 学院 > 开发设计 > 正文

UVA400

2019-11-08 18:29:21
字体:
来源:转载
供稿:网友

/*     * Copyright (c) 2017, 安徽大学计算机科学与技术学院     * All rights reserved.     * 作 者:  杨磊     * 完成日期:2017 年 02 月 16 日  * 题目描述:给定N个字符串,要求按字典序纵向排列成行列阵*                每行最大容纳60个字符,字符间距为2,以最长字符左右对齐*                假设最长的字符长为M,则最右列有M字符,其余列M+2字符。* 思路:STL sort 按字典序排列字符串再按格式输出。   */ #include<iostream>#include<string>#include<algorithm>using namespace std;const int maxlength =60;const int maxn =105;string file[maxn];void PRint(const string& s,int len,char extra){cout<<s;for(int i=0;i<len-s.length();i++)cout<<extra;}int main() {int n;while(cin>>n){        int M=0;    for(int i=0;i<n;i++){        cin>>file[i];    M=max(M,(int)file[i].length());}int cols=(maxlength-M)/(M+2)+1;int row=(n-1)/cols+1;print("",60,'-');cout<<"/n";sort(file,file+n);for(int i=0;i<row;i++) {      for(int j=0;j<cols;j++) {        int t=j*row+i;        if(t<n){            if(j==cols-1)        print(file[t],M,' ');        else            print(file[t],M+2,' ');      }}      cout << "/n";    }}  return 0;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表