400 - Unix ls

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

400 - Unix ls

Postby _.B._ » Thu Aug 18, 2005 4:07 am

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!
Last edited by _.B._ on Sat Aug 20, 2005 4:26 am, edited 1 time in total.
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

Postby daveon » Fri Aug 19, 2005 3:07 am

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

P.E. already.

Postby _.B._ » Fri Aug 19, 2005 5:23 pm

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

Thanks, but have P.E. already :o
I just can't get rid of it!!!! :evil:

Thanks anyway!

Keep posting!
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

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

Postby guayoyo » Fri Aug 19, 2005 6:05 pm

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

Thanks in advance.
10024 - Guayoyo has Curled Up the Cube!
guayoyo
New poster
 
Posts: 11
Joined: Wed Aug 17, 2005 5:59 pm
Location: Caracas, Venezuela

Input.

Postby _.B._ » Sat Aug 20, 2005 4:29 am

I/O at EOPage.
Last edited by _.B._ on Sun Aug 21, 2005 8:04 am, edited 1 time in total.
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

Postby daveon » Sat Aug 20, 2005 4:45 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...............

daveon
Experienced poster
 
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

ACed.

Postby _.B._ » Sun Aug 21, 2005 3:53 am

FINALLY!!
ACed :D
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........................
[color=darkgreen][b]_.
User avatar
_.B._
Experienced poster
 
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela

Postby ausiva » Mon May 29, 2006 8:39 pm

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;
}
ausiva
New poster
 
Posts: 6
Joined: Sun Mar 12, 2006 7:01 pm

Postby daveon » Sat Jul 22, 2006 4:14 pm

Whenever I get PE, I just leave it alone. What is the point in wasting time?
daveon
Experienced poster
 
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Indeed, what a tedious problem

Postby kogorman » Tue Dec 05, 2006 7:16 pm

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!
Kevin
kogorman
New poster
 
Posts: 14
Joined: Sat Dec 02, 2006 6:58 am

Postby daveon » Sat Dec 23, 2006 9:10 pm

daveon wrote:Whenever I get PE, I just leave it alone. What is the point in wasting time?


Oh no, the judging system just got more aggressive. Fire away until you get AC!
daveon
Experienced poster
 
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Postby hi!man! » Sun Jan 07, 2007 12:57 pm

this input
Code: Select all
3
bernardo_acm_unix_ls_accepted
finally
no_more_p_e

output should be:
Code: Select all
------------------------------------------------------------
bernardo_acm_unix_ls_accepted..
finally........................
no_more_p_e....................
hi!man!
New poster
 
Posts: 48
Joined: Fri Dec 29, 2006 1:26 pm

Postby zooom » Mon Jan 07, 2008 7:33 am

@ above .. Noo The problem says the output must span the minimum amount of rows .. In your case its 3 while output with 2 rows too is possible ..
zooom
New poster
 
Posts: 4
Joined: Tue Jun 12, 2007 9:20 am

Re: 400 > Unix ls > P.E.

Postby Obaida » Sun Aug 09, 2009 9:01 am

I can't understand the error. :oops:
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.
Obaida
A great helper
 
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 400 - Unix ls

Postby sefakilic » Tue Aug 25, 2009 3:19 pm

_.B._ wrote:FINALLY!!

ACed :D

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


Hello, I am trying to solve this problem, but getting WA.
I have a question about test case above.

In problem statement, it says
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.


In the output of ACed solution above, number of columns is 3.

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


So, the width of longest file name is 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.
sefakilic
New poster
 
Posts: 7
Joined: Wed Mar 11, 2009 8:12 pm

Next

Return to Volume IV

Who is online

Users browsing this forum: No registered users and 1 guest