uva400

Posted wantchange

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva400相关的知识,希望对你有一定的参考价值。

#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的主要内容,如果未能解决你的问题,请参考以下文章

UVA 400 - Unix ls (Unixls命令)

UVA400(有关%的使用)

Scrapy FormRequest返回400错误代码

uva是啥意思

UVA 10652 Board Wrapping(凸包)

UVA 10652 Board Wrapping(二维凸包)