Poj 1589 Unix ls

题目: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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值