Page 5 of 7

Posted: Mon Feb 27, 2006 6:50 am
by Wei-Ming Chen
code cut after AC

<note>
if you want to let a run from 0 to b or c
you can't write for(a=0;a<=b,a<=c;a++)
you should write if(b>c) b=c; for(a=0;a<=b;a++)

I did not notice that and got two WAs (ACM 200 , 400)

Posted: Tue May 23, 2006 10:20 am
by Roby
I got Runtime Error for this problem and I don't know where my mistake is. Here is my code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100
#define SIZE 65

int compare( const void * a, const void * b )
{
 return ( strcmp( ( char * ) a, ( char * ) b ) );
}

int main()
{
 int n = 0, i = 0, j = 0, r = 0, len = 0, div = 0;
 char data[MAX][SIZE];

 while ( scanf( "%d\n", &n ) == 1 )
 {
    for ( i = 0; i < n; i++ )
    {
       memset( data[i], '\0', sizeof( data[i] ) );
       gets( data[i] );
    }

    qsort( ( void * ) data, n, sizeof( data[0] ), compare );
    puts( "------------------------------------------------------------" );

    for ( i = 0, len = 0; i < n; i++ )
       if ( strlen( data[i] ) > len )
          len = strlen( data[i] );

    div = 60 / ( len + 2 );
    r = ( n % div ) ? ( ( n / div ) + 1 ) : ( n / div );

    for ( i = 0; i < r; i++ )
    {
       for ( j = 0; j < div; j++ )
       {
          int space;

          if ( i + ( j * r ) < n )
          {
             space = len - strlen( data[ i + ( j * r ) ] ) + 2;

             printf( "%s", data[ i + ( j * r ) ] );

             while ( space )
             {
                putchar( 32 );
                space--;
             }
          }
       }

       putchar( '\n' );
    }
 }

 return 0;
}
Somebody help me please... thanx

Posted: Mon May 29, 2006 8:39 pm
by ausiva
how did u get rid of the PE...i cud not no matter wat i do...ths s my code..pls let me knw if u see something missing..thanks

Code: Select all

int main()
{
    vector<string> strings;
    string temp;
    vector<string>::const_iterator iter;
    unsigned num=0;
    unsigned count=0;
    unsigned maxLength = 0;
    unsigned cols=0;
    unsigned rows=0;
    unsigned wid=0;
    int i=0;
    int j=0;

    while(cin>>num)
    {
                   getline(cin,temp);//to read the '\n' after the number
                   maxLength=rows=cols=0;
                   for(count=0;count<num;++count)
                   {
                    getline(cin,temp);
                    maxLength = max(maxLength, unsigned(temp.length()));
                    strings.push_back(temp);
                    }
                    sort(strings.begin(),strings.end());
                    //cout<<maxLength<<endl;
                    //assert(maxLength<=60);
                    cols=(60-maxLength)/(maxLength+2) + 1;
                    rows= (num%cols)?(num/cols+1):(num/cols);
                    
                    i=j=0;
                    //cout<<maxLength<<"\t"<<rows<<"\t"<<cols;
                    //draw a line of dashes
                    while(i++<60)
                                 cout<<'-';
                    for(i=0;i<rows;i++)
                    {
                           cout<<endl;
                           for(j=0;j<cols;j++)
                               if((i+j*rows)<num)
                               {
                                    cout.setf(ios::left,ios::adjustfield);
                                    wid=(j==cols-1)?(maxLength):maxLength+2;
                                    cout<<setw(wid)<<strings[i+j*rows];
                               }
                    }
                    cout<<endl;
                    strings.clear();
   }

   return 0;
}

Posted: Sat Jul 22, 2006 4:14 pm
by daveon
Whenever I get PE, I just leave it alone. What is the point in wasting time?

400 P.E.

Posted: Fri Aug 04, 2006 4:17 pm
by Anupam Pathak
hello all,
i have solved 400, but it is accepted with presentation error.... can anyone tell me what's the problem the problem.......

Please tell me..... what's wrong........
thanx.....

Posted: Fri Aug 04, 2006 7:30 pm
by emotional blind
http://acm.uva.es/cgi-bin/OnlineJudge?ProblemStat:400

look here
there is a lot more presentation error than accepted
sometimes judges output format is not accurate enough.

presentation error considered solved here,
so better remove your code from here

Indeed, what a tedious problem

Posted: Tue Dec 05, 2006 7:16 pm
by kogorman
It appears that the judge's answers do not even follow the problem specification, and one has to tease out hints from the trailing (incorrect) whitespace of the HTML sample output.

To be clear: I'm not claiming that trailing whitespace is incorrect per se, but that it does not actually conform to the problem specification about the width of the final column. Moreover, any short final line violates column widths in a different way.

What a nuisance!

Posted: Sat Dec 23, 2006 9:10 pm
by daveon
daveon wrote:Whenever I get PE, I just leave it alone. What is the point in wasting time?
Oh no, the judging system just got more aggressive. Fire away until you get AC!

Posted: Sun Jan 07, 2007 12:57 pm
by hi!man!
this input

Code: Select all

3 
bernardo_acm_unix_ls_accepted 
finally 
no_more_p_e 
output should be:

Code: Select all

------------------------------------------------------------
bernardo_acm_unix_ls_accepted..
finally........................
no_more_p_e....................

Posted: Mon Jan 07, 2008 7:33 am
by zooom
@ above .. Noo The problem says the output must span the minimum amount of rows .. In your case its 3 while output with 2 rows too is possible ..

Re: 400 > Unix ls > P.E.

Posted: Sun Aug 09, 2009 9:01 am
by Obaida
I can't understand the error. :oops:
seems very easy. some one please help me to figure out what is wrong with my code?

Code: Select all

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<ctype.h>
using namespace std;

int sort_function(const void *a, const void *b)  {

   return( strcmp((char *)a,(char *)b) );

}

int main()
{
	char st[101][61];
	int n,i,j,max,r,c,k,l;
	while(scanf("%d",&n)==1){
		max=0;
		for(i=0;i<n;i++){
			while(1){gets(st[i]);if(st[i][0]!=0)break;}
			j = strlen(st[i]);
			if(j>max)max=j;
			for(;j<61;j++){st[i][j]=' ';break;}
		}
		qsort( (void *)st,n,sizeof(st[0]),sort_function);
		c = 60/max;
		while(c*max+(c-1)*2>60&&c>=1)c--;
		if(c){
			if(n%c==0)r = n/c;
			else r = n/c+1;
		}
		else r = n;
		printf("------------------------------------------------------------\n");
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				for(k=0;st[i+j*r][k];k++){
					if(i+j*r<n){
						if(isspace(st[i+j*r][k])){
							for(l=k;l<max;l++)printf(" ");
							if(j==c-1)puts("");
							else printf("  ");
							break;
						}
						else
							printf("%c",st[i+j*r][k]);
					}
					else {puts("");break;}
				}
				if(i+j*r>=n)break;
			}
		}
	}
	return 0;
}

Re: 400 - Unix ls

Posted: Tue Aug 25, 2009 3:19 pm
by sefakilic
_.B._ wrote:FINALLY!!

ACed :D

It's such a tedious problem.
Thanks Daveon!
Here's some I/O from my ACed program that I believe will help correct P.E.s and W.A.s:


Input:

Code: Select all

5
koala.jpg
australia.exe
kangaroo.txt
foo.bar
homer.simpson

Output:

Code: Select all

------------------------------------------------------------
australia.exe..homer.simpson..koala.jpg......
foo.bar........kangaroo.txt...
Hello, I am trying to solve this problem, but getting WA.
I have a question about test case above.

In problem statement, it says
The rightmost column will be the width of the longest filename and all other columns will be the width of the longest filename plus 2. There will be as many columns as will fit in 60 characters.
In the output of ACed solution above, number of columns is 3.

But,

Code: Select all

length of "koala.jpg" = 9
length of "australia.exe" = 13
length of "kangaroo.txt" = 12
length of "foo.bar" = 7
length of "homer.simpson" = 13
So, the width of longest file name is 13.

(the width of longest file name + 2) * (number of columns - 1) + (the width of longest file name)
= (13 + 2) * (4 - 1) + 13 = 58 which is smaller than 60.

So, i think number of columns should be 4.

Can you help. thank you.

Re: 400 - Unix ls

Posted: Sun Sep 06, 2009 1:24 pm
by zobayer

Code: Select all

AC
Thanks.

Re: 400 - Unix ls

Posted: Sat Oct 10, 2009 10:12 pm
by arifcsecu
After many wrong answer
I got accepted

My approach is very simple :

1. input the string like getline(cin,s)
2. calculate the length of the maximum string
3.sort the string like sort(s,s+n)
4.calculate
ncoloum=(60-max_len)/(max_len+1) +1
nrow=(n/ncoloum)
if(n%ncoloum)
nrow++;

5.1. print (----.....---) 6o dash

5.2. now
two nested loop like

for(irow=0;irow<nrow;irow++)
for(icol=0;icol<ncoloum;icol++)
{
p=nrow*icol+irow;
if(p<n)
{
print the coressponding string as desired order loke s[p]
for(i=s[p].length();i<max_lenth;i++)
printf(" ");
}
}
6. Accepted now

Re: 400 - Unix ls

Posted: Sun Jul 11, 2010 2:02 pm
by Ahshua
Thank for your tests,I had found out my programming's deficiency,daveon !
NOw,I got Ac! :lol:
At " by daveon ยป Sat Aug 20, 2005 4:45 am "