400 - Unix ls
Moderator: Board moderators
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
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)
<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)
Last edited by Wei-Ming Chen on Mon May 29, 2006 4:55 pm, edited 1 time in total.
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
I got Runtime Error for this problem and I don't know where my mistake is. Here is my code:
Somebody help me please... thanx
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;
}
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;
}
-
- New poster
- Posts: 7
- Joined: Tue Jul 25, 2006 2:01 pm
- Contact:
400 P.E.
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.....
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.....
Last edited by Anupam Pathak on Sat Aug 05, 2006 5:31 pm, edited 1 time in total.
Trying to reduce complexity of the World.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
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
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
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!
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!
Kevin
this input
output should be:
Code: Select all
3
bernardo_acm_unix_ls_accepted
finally
no_more_p_e
Code: Select all
------------------------------------------------------------
bernardo_acm_unix_ls_accepted..
finally........................
no_more_p_e....................
Re: 400 > Unix ls > P.E.
I can't understand the error.
seems very easy. some one please help me to figure out what is wrong with my code?

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;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 400 - Unix ls
Hello, I am trying to solve this problem, but getting WA._.B._ wrote:FINALLY!!
ACed![]()
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:
Output:Code: Select all
5 koala.jpg australia.exe kangaroo.txt foo.bar homer.simpson
Code: Select all
------------------------------------------------------------ australia.exe..homer.simpson..koala.jpg...... foo.bar........kangaroo.txt...
I have a question about test case above.
In problem statement, it says
In the output of ACed solution above, number of columns is 3.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.
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
(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.
-
- Experienced poster
- Posts: 110
- Joined: Tue May 06, 2008 2:18 pm
- Location: CSE-DU, Bangladesh
- Contact:
Re: 400 - Unix ls
Code: Select all
AC
Last edited by zobayer on Sat Jul 31, 2010 8:57 pm, edited 1 time in total.
You should not always say what you know, but you should always know what you say.
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 400 - Unix ls
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
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
Try to catch fish rather than asking for some fishes.
Re: 400 - Unix ls
Thank for your tests,I had found out my programming's deficiency,daveon !
NOw,I got Ac!
At " by daveon » Sat Aug 20, 2005 4:45 am "
NOw,I got Ac!

At " by daveon » Sat Aug 20, 2005 4:45 am "