Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会WA啊 哪位 大神帮忙看一下

Posted by heia at 2014-09-01 13:15:08 on Problem 1589
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
char ans[1005][1005][105];
struct N
{
    char str[105];
}num[105];
int cmp(N a,N b)
{
    return strcmp(a.str,b.str)<0;
}
int main()
{
    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%s",num[i].str);
        sort(num,num+n,cmp);
        int maxl=-1;
        for(int i=0;i<n;i++){
            int len=strlen(num[i].str);
            if(len>maxl)
                maxl=len;
        }
        double c=floor((62*1.0)/(double)(maxl+2));
        double r=floor((double)(n-1)/(double)(c)+1);
        //printf("r=%.1lf  c=%.1lf\n",r,c);
        int k=0;
        for(int i=0;i<c&&k<n;i++)
            for(int j=0;j<r&&k<n;j++)
                strcpy(ans[j][i],num[k++].str);
        puts("------------------------------------------------------------");
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                if(ans[i][j][0]!='\0')
                    printf("%s",ans[i][j]);
                int len1=strlen(ans[i][j]);
                while(len1<maxl){
                    putchar(' ');
                    len1++;
                }
                if(j==c-1)
                    printf("\n");
                else
                    printf("  ");
            }
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator