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!
Moderator: Board moderators

daveon wrote:Would you like output from a PE code?

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
------------------------------------------------------------
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...............
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
------------------------------------------------------------
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........................

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;
}
3
bernardo_acm_unix_ls_accepted
finally
no_more_p_e ------------------------------------------------------------
bernardo_acm_unix_ls_accepted..
finally........................
no_more_p_e....................#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;
}_.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:
- 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...
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.
length of "koala.jpg" = 9
length of "australia.exe" = 13
length of "kangaroo.txt" = 12
length of "foo.bar" = 7
length of "homer.simpson" = 13Users browsing this forum: No registered users and 1 guest