Page 3 of 7

Posted: Sat Nov 29, 2003 11:05 am
by kurnia w
Hi...deddy, post your source code here...maybe i can check what wrong with your source code... :D

Posted: Sun Nov 30, 2003 2:04 pm
by deddy one
thx for your help kurnia, got Accepted now.

400 WA... @@a

Posted: Thu Mar 11, 2004 5:14 am
by Tango
please help me....

I got WA so many times ... :cry:

the following is my code:

[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int num, maxlen, cols, rows;
int size[100];
char fname[100][100];

void clean()
{
int i, j;

num = maxlen = cols = rows = 0;

for(i = 0 ; i < 100 ; i++)
{
for(j = 0 ; j < 100 ; j++)
fname[j] = '\0';
size = 0;
}
}

void print_blank(char str[])
{
int len = strlen(str);
int b_len = maxlen + 2 - len;
int i;

for(i = 0 ; i < b_len ; i++)
printf(" ");
}

void print()
{
int i, j;

for(i = 0 ; i < 60 ; i++)
printf("-");
printf("\n");

if(maxlen + 2 > 60)
cols = 1;
else
cols = 60 / (maxlen + 2);
rows = num / cols;
if(num % cols != 0)
rows += 1;

for(i = 0 ; i < rows ; i++)
{
for(j = 0 ; j < cols ; j++)
{
printf("%s", fname[i + rows * j]);
if(i == rows - 1 && j == (num % cols) - 1)
break;
if(j != cols - 1)
print_blank(fname[i + rows * j]);
}
printf("\n");
}
}

void fsize()
{
int i, tmp;

maxlen = 0;

for(i = 0 ; i < num ; i++)
{
tmp = strlen(fname);
size = tmp;
if(tmp > maxlen)
maxlen = tmp;
}
}

void sort()
{
int i, j;
char tmp[100];

for(i = 0 ; i < num - 1 ; i++)
{
for(j = i + 1 ; j < num ; j++)
{
if(strcmp(fname, fname[j]) > 0)
{
strcpy(tmp, fname[j]);
strcpy(fname[j], fname);
strcpy(fname, tmp);
}
}
}
}

int main()
{
int i;
char tmp[100];

while(fgets(tmp, sizeof(tmp), stdin) != NULL)
{
num = atoi(tmp);
for(i = 0 ; i < num ; i++)
{
fgets(tmp, sizeof(tmp), stdin);
strncpy(fname, tmp, strlen(tmp) - 1);
}
sort();
fsize();
print();
clean();
}

return 0;
}
[/c]

Re: 400 WA... @@a

Posted: Sun Mar 14, 2004 8:37 pm
by Raiyan Kamal
I think you should revise the print() function you've made. In the part where you are calculating the number of collumns and rows seems little strange to me because I did not do it in this way. May this is the problem, may be not. Would you please explain why you are doing this ?
[c]
if(maxlen + 2 > 60)
cols = 1;
else
cols = 60 / (maxlen + 2);

rows = num / cols;
[/c]

By the way, you can use memset() to clear the array instead of the clean() function you used

400 is unclear

Posted: Thu Jun 10, 2004 11:28 pm
by awbush
Problem 400 is unclear:
http://acm.uva.es/p/v4/400.html

The last sentence of the second paragraph says "Your program should use as few rows (R) as possible with rows being filled to capacity from left to right."

But in the output section it says "The sorted filenames 1 to R will be listed down column 1; filenames R+1 to 2R listed down column 2; etc." which suggests that columns should be filled to capacity and not rows.

I am aware of a solution posted at:
http://online-judge.uva.es/board/viewto ... hlight=400
but even it is only accepted with presentation error.

So which is it? Fill to capacity the rows or the columns?


Lets create a test case where columns > rows:
size=10, max_length=13 which implies 4 columns
Filling rows to capacity we have:

Code: Select all

1aaaaaaaaaaaa  4              7              9            
2              5              8              10           
3              6              
Filling columns to capacity we have:

Code: Select all

1aaaaaaaaaaaa  4              7              10           
2              5              8              
3              6              9              

Now a test case where columns < rows:
size=10, max_length=14 which implies 3 columns
Filling rowss to capacity we have:

Code: Select all

1aaaaaaaaaaaaa  5               8             
2               6               9             
3               7               10            
4               
Filling columns to capacity we have:

Code: Select all

1aaaaaaaaaaaaa  5               9             
2               6               10            
3               7               
4               8               

Perfect square test case (columns > rows or columns == rows):
size=16, max_length=10 which implies 5 columns
Filling rows to capacity we have:

Code: Select all

1aaaaaaaaa  5           8           11          14        
2           6           9           12          15        
3           7           10          13          16        
4
Filling columns to capacity we have:

Code: Select all

1aaaaaaaaa  5           9           13          ??????????
2           6           10          14          ??????????
3           7           11          15          ??????????
4           8           12          16          ??????????
                                                ^
what happened to the 5th row? ------------------|
In the perfect square test case the fifth row could be eliminated if filling columns to capacity but that should be counted wrong according the to problem statement: "There will be as many columns as will fit in 60 characters." And since the last column is to be max_length and the others max_length+2 we have 1+(60-max_length)/(max_length+2) many columns; in this case 5. I suppose a good question then would be "does an empty column still count as a column?"

It is clear that "filling rows to capacity" and "filling columns to capacity" are two different things. It seems like the correct answer is to fill rows to capacity. Maybe the problem description could be corrected?

have problems with 400 the UNIX ls one..

Posted: Wed Aug 11, 2004 10:50 pm
by kasturi
i tried all the input cases.. had gone thru the previous messages. but still get WA. i dont know why? could anyone please figure out the problem. the code is as follows:
[cpp]
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
int num; /* num indicates the number of names */
while(cin>>num)
{
char str[num][61];
unsigned int max_len=0;
for(int k=0;k<60;k++)
cout<<"-";
if(num==0)
continue;
for(int i=0;i<num;i++)
{
cin>>str;
// cout<<"\n"<<str;
int dum=strlen(str);
str[dum+1]='\0';
if(max_len<strlen(str))
max_len=strlen(str);
}
int num_r;
int num_c=(60-max_len)/(max_len+2)+1;
if(num_c!=0)
num_r=(num%num_c==0)? (num/num_c):(num/num_c+1);
else
num_c=1;
int count=0;
/* sorting */
for(int i=0;i<num;i++)
for(int j=i+1;j<num;j++)
if(strcmp(str[j],str)<0)
{
char k[60];
strcpy(k,str);
strcpy(str,str[j]);
strcpy(str[j],k);
}

/* printing in the order */
for(int i=0;i<num_r && count<num;i++)
{
// printf("\n%-*s",max_len,str);
// count++;
printf("\n");
for(int j=0;j<num_c&&count<num;j++)
{
if(j==num_c-1)
printf("%-*s",max_len,str[i+j*(num_r)]);
else
printf("%-*s",max_len+2,str[i+j*(num_r)]);
count++;
}
}
cout<<"\n";
}
}
[/cpp]

I also have another doubt. do we need to print a line for a case when input is 0 number of filenames? i tried both the cases .. one in which the output line was printed and the other in which it was not.. but there was problem with both.i got WA about 5 times. please help me. :oops:.

400 - Unix ls - PE

Posted: Thu Aug 12, 2004 3:18 am
by JaviGS
Hi!
I got PE in this problem and can't fix it!
I would be very appreciate if someone can find the bug in my code
Thanks in advance!
Regards
Javi

[cpp]

Code: Select all

Code removed
[/cpp]

Re: 400 - Unix ls - PE

Posted: Fri Aug 13, 2004 5:33 am
by Observer
There are many other posts about this issue. Please check them before posting a new topic.

400 unix ls P.E!!!

Posted: Fri Oct 29, 2004 5:24 pm
by HYri
400. unix ls

i think my answer is right.

but, always P.E

do you know any tip for 400?

how do i make a correct answer?

Posted: Sat Oct 30, 2004 6:20 am
by shamim
In 24 hr judge, PE is as good as AC, but incase you are wondering why they occur, here is the reason:

If you have extra spaces and newlines in your code, you will get PE. Since formatting of Output for this problem is more difficult than others, this problem is more prone to get PE, as extra spaces go unnoticed.

then, ?

Posted: Sat Oct 30, 2004 7:40 pm
by HYri
then how can i fix my program?

i'll show you input & output

input

Code: Select all

10
tiny
2short4me
very_long_file_name
shorter
size-1
size2
size3
much_longer_name
12345678.123
mid_size_name
12
Weaser
Alfalfa
Stimey
Buckwheat
Porky
Joe
Darla
Cotton
Butch
Froggy
Mrs_Crabapple
P.D.
19
Mr._French
Jody
Buffy
Sissy
Keith
Danny
Lori
Chris
Shirley
Marsha
Jan
Cindy
Carol
Mike
Greg
Peter
Bobby
Alice
Ruben
5
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghik
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghid
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghix
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghib
output

Code: Select all

------------------------------------------------------------
12345678.123         size-1             
2short4me            size2              
mid_size_name        size3              
much_longer_name     tiny               
shorter              very_long_file_name
------------------------------------------------------------
Alfalfa        Cotton         Joe            Porky        
Buckwheat      Darla          Mrs_Crabapple  Stimey       
Butch          Froggy         P.D.           Weaser       
------------------------------------------------------------
Alice       Chris       Jan         Marsha      Ruben     
Bobby       Cindy       Jody        Mike        Shirley   
Buffy       Danny       Keith       Mr._French  Sissy     
Carol       Greg        Lori        Peter     
------------------------------------------------------------
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghib
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghid
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghik
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghix

i really really want to get accept without P.E

Posted: Sun Oct 31, 2004 8:15 am
by shamim
It is difficult to tell, but perhpas you have extra spaces at the end of each line of output.

e.g
[c]
12345678.123 size-1
2short4me size2
mid_size_name size3
much_longer_name tiny
shorter very_long_file_name
[/c]

there could be some extra spaces in your output after size-1, Which should not be there.
Well this is just a suggestion. :roll:

Posted: Thu Nov 11, 2004 2:27 pm
by WR
I verified that there are no additional spaces but it's still P. E.! I even added spaces so that all lines within a block are equally long, doesn't work, still P. E.

After more than 10 submissions just to get rid of the presentation error I quit.

Runtime Error (SIGFPE) in 400??????

Posted: Wed Mar 23, 2005 3:16 pm
by Sakib
i just want to know what is Runtime Error (SIGFPE)??

Posted: Mon Mar 28, 2005 7:47 pm
by ..
You are doing something like this:
a = b / 0;
or
a = b % 0;
where b is an integer.

Read this:
http://online-judge.uva.es/board/viewforum.php?f=31