Page 1 of 2

10361 - Automatic Poetry

Posted: Wed Sep 18, 2002 3:58 am
by arc16
It seems easy.. but i can't get it AC. What's the trick?
In the test case, will there be something like:

Code: Select all

asdma ... asdaskdj<...>...<...>...
qwe.......qweqe ...
if so, what is the output?

thank you

Posted: Wed Sep 18, 2002 11:07 am
by henar2
The output for your input is:

asdma ... asdaskdj............
qwe.......qweqe .............

Good luck! :)

Posted: Wed Sep 18, 2002 12:27 pm
by arc16
so we only have to care about the _last_ 3 dots, is it right?

Posted: Wed Sep 18, 2002 12:33 pm
by henar2
As the problem statement says:

[quote]The second line will be a string of lowercase characters or blanks ending with three dots

10361

Posted: Sun Oct 13, 2002 3:31 am
by yahoo
Hei can anybody help me with this problem? i getting wrong answer with this problem all the time. Can anybody give any typical data to test: Here is my program:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
char a[150],b[150],c[150],d[150];
char e[150],f[150],*st;
int i,j,k,n,l;
gets(a);
n=atoi(a);
for(l=0;l<n;l++)
{
gets(a);gets(b);
for(i=0;i<strlen(a);i++)
if(a[i]=='<')
{
for(j=i+1;j<strlen(a);j++)
if(a[j]=='>')
{
for(k=i+1;k<j;k++)
c[k-i-1]=a[k];
c[k-i-1]=0;
break;
}
for(k=j+1;k<strlen(a) && a[k]!=' ';k++)
e[k-j-1]=a[k];
e[k-j-1]=0;
break;
}
for(i=j+1;i<strlen(a);i++)
if(a[i]=='<')
{
for(j=i+1;j<strlen(a);j++)
if(a[j]=='>')
{
for(k=i+1;k<j;k++)
d[k-i-1]=a[k];
d[k-i-1]=0;
break;
}
for(k=j+1;k<strlen(a)&&a[k]!=' ';k++)
f[k-j-1]=a[k];
f[k-j-1]=0;
break;
}
for(i=0;i<strlen(a);i++)
if(a[i]!='<'&& a[i]!='>')
printf("%c",a[i]);
printf("\n");
st=strstr(b,"...");
for(i=0;&b[i]!=st;i++)
printf("%c",b[i]);
printf("%s%s %s%s\n",d,e,c,f);
}
return 0;
}
/*@END_OF_SOURCE_CODE*/

Posted: Thu Oct 17, 2002 5:14 am
by soyoja
I think that some judge's input data have one or two sequential dots.

So we must consider these dots ( one or two dots ) as a string.

When I tried to solve this problem in my first time, I checked only whether

a dot appeared or not. But I got WA. So I fixed my code to check three

sequential dots. At last, I got AC. I hope that my experience help your

problem solving. Good Luck~

Posted: Thu Oct 17, 2002 8:13 am
by Dominik Michniewski
you have to replace ONLY LAST THREE DOTS ..... in input data is probably test with more then one group of three dots or more than three dots in line ... btw this problem is very easy ;-))

Best regards
Dominik

10361 WA even though I have done nothing wrong or so it seem

Posted: Sat Jul 02, 2005 7:47 pm
by gvs
Can anybody please help me... I have tried out quite a few test cases... and even with 1, 2 or more than 3 sequential dots.. which shud be treated as a string....
My prog is giving me correct output for all MY test input, but everytime it is WA.....
does anybody have any idea as to what the judge's test data might be containing which could be tripping my code ?

gvs

10361

Posted: Mon Jan 16, 2006 8:37 pm
by abhi
here is my code i get RE . y ????

Code: Select all

deleted after AC

Posted: Mon Jan 16, 2006 10:34 pm
by mamun
Increase the size of arrays s1,s2,s0,s4, at least to 101.

Posted: Tue Jan 17, 2006 4:05 am
by abhi
i changed it to

Code: Select all

 char s1[101],s2[101],s0[101],s4[101],s3[101],a[110],b[110];

still RE..........

Posted: Tue Jan 17, 2006 10:07 am
by mamun
Using scanf() and gets() at the same time is risky.
Instead of

Code: Select all

scanf("%d",&n);
write

Code: Select all

gets(a);
n=atoi(a);

Posted: Tue Jan 17, 2006 10:36 am
by abhi
thank you so much....... i got AC .. but plz tell me why it is risky to use gets() and scanf() together....... and also y i got RE ?????

Posted: Tue Jan 17, 2006 12:12 pm
by mamun
scanf() reads upto whitespace like new line and discards it whereas gets() stores the whitespace. So when you use scanf a whitespace is actually left in the buffer and immediate call to gets() causes this whitespace to be stored that is a blank line. That is why you were getting RE, trying to read from a blank string!
Writing this way also might have solved your problem

Code: Select all

scanf("%d\n",&n);

10361 Automatic poetry , PE , help

Posted: Wed Jan 25, 2006 6:45 pm
by ashikzinnatkhan
My code is:



#include <stdio.h>
#include <string.h>




void main()
{
char s1[110] , s2[110] , s3[110] , s4[110] , s5[110] , c1[200] , c2[200] , l2[200] , ch , temp[2] ;

long i , totalpair = 0 ;

scanf("%ld" , &totalpair);

for( i = 0 ; i < totalpair ; i++ )
{


strcpy(s1 , "\0");
strcpy(s2 , "\0");
strcpy(s3 , "\0");
strcpy(s4 , "\0");
strcpy(s5 , "\0");
strcpy(c1 , "\0");
strcpy(c2 , "\0");
strcpy(l2 , "\0");

fflush(stdin);


while( (ch = getchar() ) != '<' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(s1 , temp);
}

while( (ch = getchar() ) != '>' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(s2 , temp);
}

while( (ch = getchar() ) != '<' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(s3 , temp);
}

while( (ch = getchar() ) != '>' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(s4 , temp);
}

while( (ch = getchar() ) != '\n' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(s5 , temp);
}



strcpy(c1 , s1);
strcat(c1 , s2);
strcat(c1 , s3);
strcat(c1 , s4);
strcat(c1 , s5);



while( (ch = getchar() ) != '.' )
{
temp[0] = ch;
temp[1] = '\0';

strcat(l2 , temp);
}


while( (ch = getchar() ) != '\n') {}


fflush(stdin);



strcpy(c2 , l2);
strcat(c2 , s4);
strcat(c2 , s3);
strcat(c2 , s2);
strcat(c2 , s5);



printf("%s\n",c1);
printf("%s\n",c2);




}

}





It is giving PE.
Can anyone help me?
Please.