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

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

10361

Post by IRA » Sun Jan 29, 2006 8:34 am

I got WA...
Who can give me some input data and output data to test my program?
Who can help me to find the mistake?
Thanks in advance!


Code: Select all

#include <cstdio>
#include <cstring>
#include <ctype.h>

int main()
{
	char sen1[101];
	char sen2[101];
	int len1,len2;
	int i,s;
	char s1[101];
	char s2[101];
	char s3[101];
	char s4[101];
	char * p;
	int flag,f;
	int p1;
	int p2;
	int p3;
	int p4;
	int num,j;


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

	for(j=0;j<num;j++)
	{
	gets(sen1);
	gets(sen2);


	len1=strlen(sen1);
	len2=strlen(sen2);

	p1=p2=p3=p4=s=0;
	s1[0]=s2[0]=s3[0]=s4[0]=0;
	for(i=0;i<len1;i++)
	{
		if( s==0 && (isalpha(sen1[i]) || sen1[i]==' ') )
			printf("%c",sen1[i]);
		else if( s==0 && sen1[i]=='<')
			s=1;
		else if( s==1 && isalpha(sen1[i]) )
			s1[p1++]=sen1[i];
		else if( s==1 && sen1[i]=='>' )
		{
			s1[p1++]=0;
			s=2;
		}else if( s==2 && isalpha(sen1[i]) )
			s2[p2++]=sen1[i];
		else if( s==2 && sen1[i]==' ' )
		{
			s2[p2++]=0;
			s=3;
			printf("%s%s ",s1,s2);
		}else if( s==3 && sen1[i]=='<' )
			s=4;
		else if( s==4 && isalpha(sen1[i]) )
			s3[p3++]=sen1[i];
		else if( s==4 && sen1[i]=='>' )
		{
			s3[p3++]=0;
			s=5;
		}
		else if( s==5 && isalpha(sen1[i]) )
			s4[p4++]=sen1[i];
	}
	s4[p4++]=0;
	printf("%s%s\n",s3,s4);

	p=strstr(sen2,"...");
	flag=p-sen2;
	f=0;

	for(i=0;i<len2;i++)
	{
		if(i>=flag&&i<=flag+2)
		{
			if(f==0)
			{
				printf("%s%s %s%s",s3,s2,s1,s4);
				f=1;
			}
		}else
			printf("%c",sen2[i]);
	}
	printf("\n");

	}
	return 0;
}

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA » Sun Jan 29, 2006 10:46 am

I have find my mistake and got AC....
Thanks!

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

10361

Post by sakhassan » Sat Sep 16, 2006 11:44 am


I can asure u there's that there's only 3 dots(.) in the judges output. :wink:

Try this test case

ein kind haelt seinen <schn>abel intended<n>ur
wenn es haengt an der ...

ein kind haelt seinen = s1
schn = s2
abel intended = s3
n = s4
ur = s5
Best of luck

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Please help me. - 10361

Post by alamgir kabir » Tue Oct 30, 2007 5:28 pm

Thanks every body.
I have acc now.

Sayeef
New poster
Posts: 12
Joined: Sun Jun 18, 2006 3:06 am

I keep geting RE all the time can Anyone help ?? 10361

Post by Sayeef » Sun Dec 23, 2007 4:10 am

Code: Select all

#include<stdio.h>
#include<stdlib.h>

int main()
{

	int i,j,cas;
	char ch1[10]={0};
	gets(ch1);
	cas=(int)atoi(ch1);
	while(cas--)
	{
		int fl=0;
		j=0;
		char lin1[500]={'\0'},lin2[500]={'\0'},s[5][500]={'\0'},ch;
		gets(lin1);
		gets(lin2);
		for(i=0;lin1[i];i++)
		{
			if(lin1[i]=='<'||lin1[i]=='>')
			{
				fl++;
				j=0;
				s[fl][i]='\0';
			}
			else	
				s[fl][j++]=lin1[i];
		}
	printf("%s%s%s%s%s\n",s[0],s[1],s[2],s[3],s[4]);
	for(i=0;lin2[i];i++)
	{
		if(lin2[i]!='.')
			printf("%c",lin2[i]);
		else
		{
			printf("%s%s%s%s\n",s[3],s[2],s[1],s[4]);
			break;
		}
	}


	}

return 1;
}

Samiul
New poster
Posts: 36
Joined: Thu Dec 13, 2007 3:01 pm

Post by Samiul » Sun Dec 23, 2007 1:16 pm

You can't return 1. It will give RE.

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 10361 - Automatic Poetry

Post by Imti » Thu Dec 16, 2010 4:08 pm

It is logical that we should replace s4s3s2s5 with three consecutive dots.But my accepted solution did not care with three consecutive dots.It just has replaced
the string s4s3s2s5 when it encounters any first dot like below...
1
it is <me>ok <yes>!
ami .. eta ...
it is meok yes!
ami yesok me!

and its accepted... :D .What about this?
For those who are getting WA dont print any string of zero length.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10361 - Automatic Poetry

Post by plamplam » Thu Jul 14, 2011 10:26 pm

"The second line will be a string of lowercase characters or blanks ending with three dots ...". You don't need to check for dots.

Code: Select all

len = strlen(second_string);
for (j = 0; j < len - 3; j++){
    printf("%c", second_string[j]);
}
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10361 - Automatic Poetry

Post by plamplam » Thu Jul 14, 2011 10:29 pm

@Imti....your solution is not supposed to get Accepted. I guess the judge input is very weak...The correct output should be

Code: Select all

it is meok yes!
ami .. eta yesok me!
nvm....
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10361 - Automatic Poetry

Post by uDebug » Sat Feb 22, 2014 3:02 pm

Here's some input / output that I found useful during testing / debugging.

Input:

Code: Select all

2
lorem ipsum dolor sit amet consectet<ur adip>iscing      <>       elit
  ut ut condimentum nulla ac tincidunt lectus               ...
<nam in est et odio cursus               >     <vestibulu>
...
AC Output:

Code: Select all

lorem ipsum dolor sit amet consectetur adipiscing             elit
  ut ut condimentum nulla ac tincidunt lectus               iscing      ur adip       elit
nam in est et odio cursus                    vestibulu
vestibulu     nam in est et odio cursus               
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

aseem_cu
New poster
Posts: 2
Joined: Wed Jun 01, 2016 11:27 am

Re: 10361 - Automatic Poetry

Post by aseem_cu » Wed Jun 01, 2016 11:38 am

10361 - Automatic Poetry:
Why I'm getting wrong answer?? I'm testing debug input/output, All input/output are ok!

#include<bits/stdc++.h>
using namespace std;
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define PI acos(-1.0)
#define LL long long
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
int main()
{
//freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
int test;
string s1,s2,s;
vector<string>v1;
//getchar();

cin>>test;
getchar();
// cin.clear();
//cin.sync();
while(test--)
{
v1.clear();
getline(cin,s1);
getline(cin,s2);
//cout<<"s1 = "<<s1<<endl;
//cout<<"s2 = "<<s2<<endl;
s="";
for(int i=s1.length()-1; i>=0; i--)
{
if(s1=='>' ||s1=='<')
{
reverse(s.begin(),s.end());
v1.push_back(s);
//cout<<" s = "<<s<<endl;
s="";
}
else
{
s+=s1;
}
}
/*for(int i=0;i<v1.size();i++)
{
cout<<v1<<" ";
}
cout<<endl;*/
string ss="";
for(int i=0; i<s1.length(); i++)
{
if(s1!='<' && s1!='>')
{
ss+=s1;
}
/*else
{
ss+=" ";
}*/
}
cout<<ss<<endl;
if(s2!="...")
{
string sss="";
for(int i=0; i<s2.length()-4; i++)
{


sss+=s2;

}
//cout<<"sss = "<<sss<<endl;
cout<<sss<<" "<<v1[1]<<v1[2]<<v1[3]<<v1[0]<<endl;
}
else


cout<<v1[1]<<v1[2]<<v1[3]<<v1[0]<<endl;
}

}

Post Reply

Return to “Volume 103 (10300-10399)”