10361 - Automatic Poetry

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

Moderator: Board moderators

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

10361 - Automatic Poetry

Post by arc16 » Wed Sep 18, 2002 3:58 am

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

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am
Location: Valladolid (Spain)

Post by henar2 » Wed Sep 18, 2002 11:07 am

The output for your input is:

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

Good luck! :)

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 » Wed Sep 18, 2002 12:27 pm

so we only have to care about the _last_ 3 dots, is it right?

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am
Location: Valladolid (Spain)

Post by henar2 » Wed Sep 18, 2002 12:33 pm

As the problem statement says:

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

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

10361

Post by yahoo » Sun Oct 13, 2002 3:31 am

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*/

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja » Thu Oct 17, 2002 5:14 am

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~

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Thu Oct 17, 2002 8:13 am

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

gvs
New poster
Posts: 6
Joined: Sun Jun 19, 2005 7:39 pm

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

Post by gvs » Sat Jul 02, 2005 7:47 pm

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
maKe wHat yoU waNt...... you'll succeed

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

10361

Post by abhi » Mon Jan 16, 2006 8:37 pm

here is my code i get RE . y ????

Code: Select all

deleted after AC
Last edited by abhi on Tue Jan 17, 2006 10:37 am, edited 1 time in total.

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Mon Jan 16, 2006 10:34 pm

Increase the size of arrays s1,s2,s0,s4, at least to 101.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Tue Jan 17, 2006 4:05 am

i changed it to

Code: Select all

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

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

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Tue Jan 17, 2006 10:07 am

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);

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Tue Jan 17, 2006 10:36 am

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 ?????

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Tue Jan 17, 2006 12:12 pm

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);

ashikzinnatkhan
New poster
Posts: 8
Joined: Wed Jan 25, 2006 6:25 pm
Location: Dhaka, Bangladesh

10361 Automatic poetry , PE , help

Post by ashikzinnatkhan » Wed Jan 25, 2006 6:45 pm

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.
Ashik

Post Reply

Return to “Volume 103 (10300-10399)”