## 400 - Unix ls

Moderator: Board moderators

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland
I've got also P.E. and I really dont know how to fix it too.
Have anyone got AC?
keep it real!

roticv
Learning poster
Posts: 63
Joined: Sat Dec 11, 2004 9:28 am
Try making an input with 5 rows and 4 columns but only 15 entries.

Do you print extra spaces for this special case? I got alot of WA because of it

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland
no extra spaces maybe the rest of row should be filled with spaces so that all 60 signs occur?
keep it real!

59557RC
New poster
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Contact:

### 400-WA any1 pls help

i had been stack in this prob. 4 many days.can any1 pls help me.
what's wrong:
#include<stdio.h>
#include<string.h>

int main(void)
{

char str[100][61],temp[61];
int c,r,i,j,k,n,s,t,len[100],max;

while(scanf("%d",&n) !=EOF){max=0;
for(i=0;i<n;i++) {scanf("%s",str);
if(max<strlen(str)) max=strlen(str);}

for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(strcmp(str,str[j])>0){
strcpy(temp,str);
strcpy(str,str[j]);
strcpy(str[j],temp); }
}
}
for(i=0;i<n;i++) len=strlen(str);

c=60/(max+2);
if(c>n) c=n;
if(c<1) c=1;
if(n%c==0) r=n/c;
else r=n/c+1;

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

t=0;s=0;
for(i=0;i<r;i++) {
printf("\n");
for(j=0;j<c;j++) {
printf("%s",str[s+t]);
for(k=max+2;k>=len[s+t];k--) printf(" ");
t+=r;}

s++;t=0;}
printf("\n");

}

return 0;
}
aaa

59557RC
New poster
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Contact:
i think i outputted correctly.so why WA:

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

int main(void)
{

char str[100][61],temp[61];
int c,r,i,j,k,n,s,t,ma,len[100],max;

while(scanf("%d",&n) !=EOF){max=0;
for(i=0;i<n;i++) {scanf("%s",str);
if(max<strlen(str)) max=strlen(str);}

for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(strcmp(str,str[j])>0){
strcpy(temp,str);
strcpy(str,str[j]);
strcpy(str[j],temp); }
}
}
for(i=0;i<n;i++) len=strlen(str);

c=60/(max+2);
if(c>n) c=n;
if(c<1) c=1;
if(n%c==0) r=n/c;
else r=n/c+1;

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

t=0;s=0;
for(i=0;i<r;i++) {
printf("\n");
for(j=0;j<c;j++) {
printf("%s",str[s+t]);
if(j=c-1) ma=max;
else ma=max+2;
for(k=ma;k>=len[s+t];k--) printf(" ");
t+=r;}

s++;t=0;}
printf("\n");

}

return 0;
}
aaa

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### 400 - Unix ls

Greetings!
Will anyone ACed please post the output for this input?
IF possible, change whitespace character by any other character, or try to post it between "code" quotes.

Last edited by _.B._ on Sat Aug 20, 2005 4:26 am, edited 1 time in total.
_.

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Would you like output from a PE code?

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Heya daveon!
daveon wrote:Would you like output from a PE code?
I just can't get rid of it!!!!

Thanks anyway!

Keep posting!
_.

guayoyo
New poster
Posts: 11
Joined: Wed Aug 17, 2005 5:59 pm
Location: Caracas, Venezuela

### I want the P.E. output... please...

Daveon, can you give me the correct output for ._B_. input, i've got WA many times...

10024 - Guayoyo has Curled Up the Cube!

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### Input.

I/O at EOPage.
Last edited by _.B._ on Sun Aug 21, 2005 8:04 am, edited 1 time in total.
_.

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
To guayoyo, seems like Bernardo made slight changes to his input.

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
4
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgz
123456789112345678921234567893123456789412345678951234567896
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh
123456789112345678921234567893123456789412345678951234567896
9
tiny
2short4me
very_long_file_name
shorter
size-1
much_longer_name
12345678.123
mid_size_name
z
52
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
z
y
x
w
v
u
t
s
r
q
p
o
n
m
l
k
j
i
h
g
f
e
d
c
b
a
11
tiny
2short4me
very_long_file_name
shorter
size-1
size2
size3
much_longer_name
12345678.123
mid_size_name
zz
``````
OUTPUT:
. represents a blank space

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.......
------------------------------------------------------------
123456789112345678921234567893123456789412345678951234567896
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgz
------------------------------------------------------------
12345678.123.........size-1...............
2short4me............tiny.................
mid_size_name........very_long_file_name..
much_longer_name.....z....................
shorter..............
------------------------------------------------------------
a..c..e..g..i..k..m..o..q..s..u..w..y..
b..d..f..h..j..l..n..p..r..t..v..x..z..
------------------------------------------------------------
12345678.123.........size2................
2short4me............size3................
mid_size_name........tiny.................
much_longer_name.....very_long_file_name..
shorter..............zz ..................
size-1...............

``````

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### ACed.

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:

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
4
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgz
123456789112345678921234567893123456789412345678951234567896
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh
123456789112345678921234567893123456789412345678951234567896
9
tiny
2short4me
very_long_file_name
shorter
size-1
much_longer_name
12345678.123
mid_size_name
z
52
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
z
y
x
w
v
u
t
s
r
q
p
o
n
m
l
k
j
i
h
g
f
e
d
c
b
a
11
tiny
2short4me
very_long_file_name
shorter
size-1
size2
size3
much_longer_name
12345678.123
mid_size_name
zz
5
koala.jpg
australia.exe
kangaroo.txt
foo.bar
homer.simpson
2
www_algorithmist_com
acm.uva.es
3
bernardo_acm_unix_ls_accepted
finally
no_more_p_e
``````
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.......
------------------------------------------------------------
123456789112345678921234567893123456789412345678951234567896
123456789112345678921234567893123456789412345678951234567896
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgz
------------------------------------------------------------
12345678.123.........size-1.............
2short4me............tiny...............
mid_size_name........very_long_file_name
much_longer_name.....z..................
shorter..............
------------------------------------------------------------
a..b..d..e..g..h..j..k..m..n..p..q..s..t..v..w..y..z..
a..c..d..f..g..i..j..l..m..o..p..r..s..u..v..x..y..
b..c..e..f..h..i..k..l..n..o..q..r..t..u..w..x..z..
------------------------------------------------------------
12345678.123.........size2..............
2short4me............size3..............
mid_size_name........tiny...............
much_longer_name.....very_long_file_name
shorter..............zz.................
size-1...............
------------------------------------------------------------
australia.exe..homer.simpson..koala.jpg......
foo.bar........kangaroo.txt...
------------------------------------------------------------
acm.uva.es............www_algorithmist_com
------------------------------------------------------------
bernardo_acm_unix_ls_accepted..no_more_p_e..................
finally........................
``````
_.

New poster
Posts: 42
Joined: Sun Jul 31, 2005 2:07 am
Contact:
does it run ok on your PC ??

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

what is the output of

Code: Select all

``````16
1
2aaaaaaaaa
3
4
5
6
7
8
9
10
11
12
13
14
15
16``````
thanks..
I tried this problem all the afternoon and got WA

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore
Output from my AC code:

Code: Select all

``````------------------------------------------------------------
1           13          2aaaaaaaaa  6
10          14          3           7
11          15          4           8
12          16          5           9
``````
Hope this helps.