848 - Fmt
Moderator: Board moderators
848 - Fmt
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.
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.
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
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
What is the difference between empty line and blank line? I also assume that line break is '\n'. Is my assumption correct?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.
Wow...
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
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

Mine worked after fixing this bug:
The input:
Where * are spaces, should output:
With no spaces, as you can see.
The input:
Code: Select all
a
***
b
Code: Select all
a
b
Re: ???
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
Besides, beware the EOF marker.Output wrote: aaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa_bbbbb
bbbbb_ccccc
_____ccccc
ddddd
_____ddddd
eeeee
_____eeeee
fffff______fffff
mmm, anyone can say me what's wrong??
I'm getting WA, and I don't know why....
thanks
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
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.
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
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.
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
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.
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
One more point. The output must end with end of line character.