题目:http://poj.org/problem?id=1589
水题。字符串排序。
但是本题数据是怎么回事,在Poj上过的了,在Hoj上过不了。不知怎么回事。有看明白是为啥的麻烦回复一下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;
string c[65];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n;
while(scanf(" %d",&n)!=EOF)
{
int mLen = 0;
for(int i=1;i<=n;i++)
{
cin>>c[i];
if(c[i].length() > mLen) mLen = c[i].length();
}
//默认是按照字典序排序
sort(c+1,c+n+1);
int col = (60 - mLen)/(mLen + 2) + 1;
int row = n/col;
if(n%col!=0) row++;
for(int i=1;i<=60;i++)
{
printf("-");
}
printf("\n");
for(int i = 1;i<=row;i++)
{
for(int j=1;j<=col;j++)
{
int cur = i + (j-1)*row;
if(cur>n)
{
break;
}
printf("%s",c[cur].c_str());
if(j!=col && cur!=n)
{
for(int k=1;k<=mLen-c[cur].length()+2;k++)
{
printf(" ");
}
}
}
printf("\n");
}
}
return 0;
}