Page 1 of 2

848 - Fmt

Posted: Sat Aug 02, 2003 4:45 am
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.

Posted: Sat Sep 27, 2003 8:14 am
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

Posted: Sat Sep 27, 2003 8:16 am
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

Posted: Thu Oct 23, 2003 11:00 am
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?

Wow...

Posted: Sun Jun 12, 2005 10:07 pm
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

Posted: Wed Oct 12, 2005 8:04 am
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.

Posted: Sat Feb 11, 2006 10:26 pm
by cytmike
Can anybody who got AC post some critical test case? This problem is driving me insane after getting 30 WA... :cry:

???

Posted: Wed May 03, 2006 4:35 am
by ligod
Hello,every1
if input has 2 or more spaces
should it be replaced by only 1 space?
thanks for your answer

Re: ???

Posted: Fri Jan 04, 2008 2:06 pm
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.

Posted: Wed Jan 16, 2008 4:26 am
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;
}

Re: Problem 848 - FMT

Posted: Mon Apr 07, 2008 6:51 pm
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.

Re: 848 - FMT

Posted: Tue Apr 08, 2008 2:30 pm
by Jan
Try the I/O files .

Input
Output

Hope these help.

Re: 848 - FMT

Posted: Mon May 12, 2008 3:41 pm
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.

Re: 848 - FMT

Posted: Fri May 16, 2008 10:56 pm
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.

Re: 848 - FMT

Posted: Wed May 28, 2008 2:20 pm
by poixp
One more point. The output must end with end of line character.