400 - Unix ls
Moderator: Board moderators
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;
}
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
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;
}
#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
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.
Thanks in advance!
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.
Thanks in advance!
Last edited by _.B._ on Sat Aug 20, 2005 4:26 am, edited 1 time in total.
_.
P.E. already.
Heya daveon!
I just can't get rid of it!!!!
Thanks anyway!
Keep posting!
Thanks, but have P.E. alreadydaveon wrote:Would you like output from a PE code?
I just can't get rid of it!!!!
Thanks anyway!
Keep posting!
_.
I want the P.E. output... please...
Daveon, can you give me the correct output for ._B_. input, i've got WA many times...
Thanks in advance.
Thanks in advance.
10024 - Guayoyo has Curled Up the Cube!
To guayoyo, seems like Bernardo made slight changes to his input.
INPUT:
OUTPUT:
. represents a blank space
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
. 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...............
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:
Output:
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
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
- Location: SUST. Bangladesh
- Contact:
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
ACM 400 please help
what is the output of
thanks..
I tried this problem all the afternoon and got WA
Code: Select all
16
1
2aaaaaaaaa
3
4
5
6
7
8
9
10
11
12
13
14
15
16
I tried this problem all the afternoon and got WA
Output from my AC code:
Hope this helps.
Code: Select all
------------------------------------------------------------
1 13 2aaaaaaaaa 6
10 14 3 7
11 15 4 8
12 16 5 9