UVA 400

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j;
    while(cin>>n)
    {
        vector<string> vs;
        int max_len=0,col=1,hang=0;
        string temp;
        for(i=0;i<n;i++)
        {
            cin>>temp;
            vs.push_back(temp);
            if(vs[i].length()>max_len)
                max_len=vs[i].length();
        }
        while(true)
        {
            if((col*(max_len+2)+max_len)<=60)
            {
                col++;
            }
            else  break;
        }
        sort(vs.begin(),vs.end());
        if(n%col==0)
            hang =n/col;
        else
            hang=n/col+1;
        cout<<"------------------------------------------------------------"<<endl;
        for(j=0;j<hang;j++)
        {
            for(i=0;i<col;i++)
            {
                if((i*hang+j)<n)
                {
                    cout<<vs[i*hang+j];
                    for(int k=0;k<(max_len+2-vs[i*hang+j].length());k++)
                        cout<<" ";
                }
            }
            cout<<endl;
        }
    }
    return 0;
}

 

posted @ 2012-04-28 12:00  open your eyes  阅读(262)  评论(0编辑  收藏  举报