码迷,mamicode.com
首页 > 其他好文 > 详细

uva400

时间:2019-04-02 19:48:48      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:ret   ios   setw   algorithm   print   scanf   i++   tor   cst   

#include <cstdio>
#include <cstdlib>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<set>
#include<iomanip>
#include<map>
#include<queue>
#include<sstream>
#include<ctype.h>
using namespace std;
int main()
{
    int n;
    string filename[105];
    int tu[105][100];
    while (scanf("%d",&n)!=-1)
    {
        int maxn=1,cnt=0;
        map<int,string>s;
        for (int i=0; i<n; i++)
        {
            cin>>filename[i];
            if ((int)filename[i].length()>maxn)
                maxn=(int)filename[i].length();
        }
        sort(filename,filename+n);
        for (int i=0;i<n;i++)
            s[i]=filename[i];
        int c=62/(maxn+2);
        int r;
        if (n%c==0)
            r=n/c;
        else
            r=n/c+1;
        //cout<<r<<endl<<c;
        for (int j=0; j<c; j++)
        {
            for (int i=0; i<r; i++)
            {
                tu[i][j]=cnt;
                cnt++;
            }
        }
//        for (int i=0; i<r; i++)
//        {
//            for (int j=0; j<c; j++)
//            {
//                if (j==c-1)
//                    cout<<tu[i][j]<<endl;
//                else
//                    cout<<tu[i][j];
//            }
//
//        }
        int left=n-r*(c-1);
        cout<<setiosflags(ios::left);
         for (int i=1;i<=60;i++)
            printf("-");
         printf("\n");
        for (int i=0;i<r;i++)
        {
            for (int j=0;j<c;j++)
            {
                if (i<left)
                {
                    if (j!=c-1)
                    {
                        cout<<setw(maxn+2)<<s[tu[i][j]];
                    }
                    if (j==c-1)
                    {
                        cout<<setw(maxn)<<s[tu[i][j]]<<endl;
                    }
                }
                else
                {
                    if (j<c-2)
                    {
                        cout<<setw(maxn+2)<<s[tu[i][j]];
                    }
                    if (j==c-2)
                    {
                        cout<<setw(maxn+2)<<s[tu[i][j]]<<endl;
                    }
                }
            }
        }

    }

    return 0;
}

uva400

标签:ret   ios   setw   algorithm   print   scanf   i++   tor   cst   

原文地址:https://www.cnblogs.com/wantchange/p/10644743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!