848 - FMT

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

Moderator: Board moderators

848 - FMT

Postby Sebasti » Sat Aug 02, 2003 4:45 am

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.
Sebasti
New poster
 
Posts: 10
Joined: Sun Apr 13, 2003 11:41 pm

Postby symme7ry » Sat Sep 27, 2003 8:14 am

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

Postby symme7ry » Sat Sep 27, 2003 8:16 am

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
symme7ry
New poster
 
Posts: 7
Joined: Fri Aug 22, 2003 10:23 am

Postby BiK » Thu Oct 23, 2003 11:00 am

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?
BiK
Experienced poster
 
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

Wow...

Postby dpitts » Sun Jun 12, 2005 10:07 pm

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
dpitts
New poster
 
Posts: 31
Joined: Tue Jun 17, 2003 10:10 pm

Postby AC/DC J » Wed Oct 12, 2005 8:04 am

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.
AC/DC J
New poster
 
Posts: 4
Joined: Sun Sep 18, 2005 6:50 am

Postby cytmike » Sat Feb 11, 2006 10:26 pm

Can anybody who got AC post some critical test case? This problem is driving me insane after getting 30 WA... :cry:
Impossible is Nothing.
User avatar
cytmike
Learning poster
 
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States

???

Postby ligod » Wed May 03, 2006 4:35 am

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

Re: ???

Postby DJWS » Fri Jan 04, 2008 2:06 pm

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.
DJWS
Learning poster
 
Posts: 100
Joined: Sat Oct 11, 2003 3:30 pm
Location: Taiwan

Postby kamiloj » Wed Jan 16, 2008 4:26 am

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;
}
kamiloj
New poster
 
Posts: 9
Joined: Fri Dec 29, 2006 3:34 pm

Re: Problem 848 - FMT

Postby dplt » Mon Apr 07, 2008 6:51 pm

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.
dplt
New poster
 
Posts: 4
Joined: Thu Feb 15, 2007 4:30 pm
Location: Indonesia

Re: 848 - FMT

Postby Jan » Tue Apr 08, 2008 2:30 pm

Try the I/O files .

Input
Output

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Re: 848 - FMT

Postby mpi » Mon May 12, 2008 3:41 pm

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.
mpi
New poster
 
Posts: 46
Joined: Fri Nov 03, 2006 7:53 pm
Location: Madrid

Re: 848 - FMT

Postby nicolai » Fri May 16, 2008 10:56 pm

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.
nicolai
New poster
 
Posts: 5
Joined: Fri May 16, 2008 10:38 pm
Location: Ukraine / Germany

Re: 848 - FMT

Postby poixp » Wed May 28, 2008 2:20 pm

One more point. The output must end with end of line character.
poixp
New poster
 
Posts: 20
Joined: Mon Apr 07, 2008 11:05 am

Next

Return to Volume VIII

Who is online

Users browsing this forum: No registered users and 1 guest