848 - Fmt

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

Moderator: Board moderators

Sebasti
New poster
Posts: 10
Joined: Sun Apr 13, 2003 11:41 pm
Contact:

848 - Fmt

Post by Sebasti »

Hi,

Anyone have test cases of this problem?
What is the output when the line starts with blanks and have a word of size 73?

Bye,
Sebastiao.

symme7ry
New poster
Posts: 7
Joined: Fri Aug 22, 2003 10:23 am

Post by symme7ry »

I just solved this problem after much trouble. It appears that the test data for this problem is possibly wrong. The straightforward greedy method does not optimize the line lengths, but the test data seems to be based on this algorithm.

To answer your question, if you have spaces and then a 73 character string, the first step is to add a newline right before the long string, then remove the spaces that preceded the long string, then print the long string on the following line.

For instance
aaa
aaaaaaaaaaaaaaaaaa<assume 73 chars>
aaa

this transforms into:
aaa

aaaaaaaaaaaaaaaaaaa<etc>
aaa

At least that it what my algorithm does, and mine got AC

symme7ry
New poster
Posts: 7
Joined: Fri Aug 22, 2003 10:23 am

Post by symme7ry »

My spaces did not appear in the post. What I wrote was


For instance:
aaa
___aaaaaaaaaaaaaaaaaa<assume 73 chars>
aaa


turns into:

aaa

aaaaaaaaaaaaaaaaaa<assume 73 chars>
aaa

..where _ means space

BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

Post by BiK »

A line break in the input may be eliminated in the output, provided it is not at the end of a blank or empty line and is not followed by a space or another line break. If a line break is eliminated, it is replaced by a space.
What is the difference between empty line and blank line? I also assume that line break is '\n'. Is my assumption correct?

dpitts
New poster
Posts: 31
Joined: Tue Jun 17, 2003 10:10 pm

Wow...

Post by dpitts »

That little phrase "end of a blank or empty line" escaped me.
I didn't even notice that it was there for a while, and when I did, it caused a little grief. But now I'm AC!!!

The trick, for those who care, is that empty lines (lines with only spaces) should be converted to blank lines (a line with only a \n)

This is because no space should end a line, and an empty line has a space at the end ;-)

Nice little trick there problem setter :-D

AC/DC J
New poster
Posts: 4
Joined: Sun Sep 18, 2005 6:50 am

Post by AC/DC J »

Mine worked after fixing this bug:

The input:

Code: Select all

a
***
b
Where * are spaces, should output:

Code: Select all

a

b
With no spaces, as you can see.

cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

Post by cytmike »

Can anybody who got AC post some critical test case? This problem is driving me insane after getting 30 WA... :cry:
Impossible is Nothing.

ligod
New poster
Posts: 1
Joined: Wed May 03, 2006 4:32 am

???

Post by ligod »

Hello,every1
if input has 2 or more spaces
should it be replaced by only 1 space?
thanks for your answer

DJWS
Learning poster
Posts: 100
Joined: Sat Oct 11, 2003 3:30 pm
Location: Taiwan
Contact:

Re: ???

Post by DJWS »

Spaces need to be reserved, except the specific eliminations by rules.
Input (Spaces are replaced by '_') wrote: aaa
_____aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa
bbbbb______________________________________________________________________
bbbbb
ccccc______________________________________________________________________
_____ccccc

ddddd_____
_____ddddd

eeeee
_____eeeee

fffff_____
fffff
Output wrote: aaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa_bbbbb
bbbbb_ccccc
_____ccccc

ddddd
_____ddddd

eeeee
_____eeeee

fffff______fffff
Besides, beware the EOF marker.

kamiloj
New poster
Posts: 9
Joined: Fri Dec 29, 2006 3:34 pm

Post by kamiloj »

mmm, anyone can say me what's wrong??
I'm getting WA, and I don't know why....
thanks

Code: Select all


#include <iostream>

using namespace std;

bool a=true;

void print(char * linea){
     //corregir
     int len=72, i, j, k;
     
     for(k=len;k>=0&&linea[k]!=' ';k--);
     
     for(j=k;j>=0&&linea[j]==' ';j--);
     
     for(i=0;i<=j;i++){
     cout<<linea[i];
     }

     if(j<0)
     j=0;
     
     len=strlen(linea);
     for(i=len-1;i>=0&&linea[i]==' ';i--);
     len=i+1;
     for(i=k+1, k=0;i<len;i++)
     linea[k++]=linea[i];
     linea[k]='\0';

     if(k>72){
       if(a)
        {
          a=false;
          print(linea);
          a=true;
          return;
        }
        else{
        cout<<endl;
        for(;linea[len]==' ';len--);
        for(i=j;i<len;i++){
         cout<<linea[i];
         }
         linea[0]='\0';
        }
     }
              
     cout<<endl;
     
     
}
     
void print2(char * linea, char *linea2){
     int len=strlen(linea)-1;
     for(;len>=0&&linea[len]==' ';len--);

     for(int i=0;i<=len;i++)
     cout<<linea[i];
     
     if(linea[0]!='\0')
     cout<<endl;
     
     len=strlen(linea2)-1;
     for(;len>=0&&linea2[len]==' ';len--);
     
     
     if(len<=0){
     cout<<endl;
     linea[0]='\0';
     return;
     }
     
     strcpy(linea,linea2);
     }  

int main(int argc, char *argv[])
{
    freopen("entrada.in","r",stdin);
    freopen("salida.in","w",stdout);  
    
   char lSig[400], lAnt[400];
   lAnt[0]='\0';
   
   while(gets(lSig)){
     
     if(lSig[0]==0||lSig[0]==' '){
     print2(lAnt,lSig);
     }
     
     else{
          if(lAnt[0]!='\0')
     strcat(lAnt, " ");
     strcat(lAnt, lSig);
     }

     if(strlen(lAnt)>72)
     print(lAnt);
     
   }
   int k,i;
   for(k=strlen(lAnt)-1;k>=0&&lAnt[k]==' ';k--);
   for(i=0;i<=k;i++)
   cout<<lAnt[i];
   if(i>0)
   cout<<endl;
    return 0;
}

dplt
New poster
Posts: 4
Joined: Thu Feb 15, 2007 4:30 pm
Location: Indonesia
Contact:

Re: Problem 848 - FMT

Post by dplt »

I've been trying to solve this problem and got 20 WAs so far.
is there any tricky case in judge inputs?
is it required to add an extra new line at the end of the output?

i've already passed all the sample IO which is written on the previous posts.
But still Wrong Answer at all.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 848 - FMT

Post by Jan »

Try the I/O files .

Input
Output

Hope these help.
Ami ekhono shopno dekhi...
HomePage

mpi
New poster
Posts: 46
Joined: Fri Nov 03, 2006 7:53 pm
Location: Madrid

Re: 848 - FMT

Post by mpi »

Thanks Jan for the I/O files. They really helped me a lot!
However, I must say that my AC program doesn't produce *exactly* the same output as the sample output file, so it's not necessary to make them match perfectly. You can use them as a guide, though.

nicolai
New poster
Posts: 5
Joined: Fri May 16, 2008 10:38 pm
Location: Ukraine / Germany

Re: 848 - FMT

Post by nicolai »

to Jan:

Thanks a lot for your tastcase, but i think your output file is not correct. Consider 8th line of the input file: you can't remove the newline character at the end of this line, because it is followed by a blank. So the 9th line

_uikgLnWMYC IaqTSKALISxCVyRaZDxXMdltxKxensTbCq

should stay unchanged.

poixp
New poster
Posts: 20
Joined: Mon Apr 07, 2008 11:05 am

Re: 848 - FMT

Post by poixp »

One more point. The output must end with end of line character.

Post Reply

Return to “Volume 8 (800-899)”