630 - Anagrams (II)

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

Moderator: Board moderators

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Well...

Post by _.B._ » Sat Sep 04, 2004 1:51 am

I found only 2 differences between the I/Os I've tried.
They are:

1. You'll have to "trim" blank spaces at the beginning and/or the end of every word. I made this one in Pascal, and I only read valid chars to build the words.
I believe the input MAY have words with blank spaces at the beginning or end of words.

2. Your code prints an extra blank line at the end of the output. That should only represent a P.E., not a W.A.
Just use a bool Flag = false; or a counter, like:
[cpp] n=atoi(word2.original);
if (Flg)
cout << endl;
Flg = true;[/cpp]

That's all my C++ knoledge can do for you rigth now :wink:
Hope that helps.
_.

wolf
New poster
Posts: 34
Joined: Sun Aug 22, 2004 4:20 am
Location: Poland

Post by wolf » Sat Sep 04, 2004 2:19 am

I did what you said, but still WA. Notwithstanding, thanx for checking my program :-D Maybe I will try to do this in Pascal in the future, like you, but I haven't used this language since last year !!! This could be a challange :-)

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Maybe this.

Post by _.B._ » Sat Sep 04, 2004 7:14 pm

Heya Wolf!
It's a pity I couldn't be of more help.
Well, since we are gussing the input for this problem due to the lack of description, LAST thing I can think of is that the input looks like this (since others look like this too):

Code: Select all

3

8
lato
atol
microphotographics
rata
rola
tara
tola
pies
tola
kola
aatr
photomicrographics
END

5
xxx
loka
kola
kola
loka
kola
photomicrographics
xxx
END

0
abcde
fgh
microphotographics
END
Output:

Code: Select all

Anagrams for: tola
  1) lato
  2) atol
  3) tola
Anagrams for: kola
No anagrams for: kola
Anagrams for: aatr
  1) rata
  2) tara
Anagrams for: photomicrographics
  1) microphotographics

Anagrams for: kola
  1) loka
  2) kola
  3) kola
  4) loka
Anagrams for: photomicrographics
No anagrams for: photomicrographics
Anagrams for: xxx
  1) xxx

Anagrams for: abcde
No anagrams for: abcde
Anagrams for: fgh
No anagrams for: fgh
Anagrams for: microphotographics
No anagrams for: microphotographics

My program gives rigth answer, yours don't.
I don't know, do a
[cpp]while (cin.peek() == '\n')
cin.get();[/cpp]
or something like that.
Good luck!

Keep posting!
Last edited by _.B._ on Sat Sep 04, 2004 11:59 pm, edited 1 time in total.
_.

wolf
New poster
Posts: 34
Joined: Sun Aug 22, 2004 4:20 am
Location: Poland

Post by wolf » Sat Sep 04, 2004 9:40 pm

Finaly I make some changes and ... got AC !!! It's my 50 AC problem now !!! (magic number :-D ). Thank you very much _.B._ The last version of input you posted was absolutely right and (for those who will propably have problems with 630 in the future) the input has NO extra spaces.

It's a pity that the problem description is completly different with right form!

Best regard,
Wolf

P.S. I'll remove my code form above :lol:

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Good!

Post by _.B._ » Sat Sep 04, 2004 11:54 pm

Glad I could help ;)
Gratz on your 50 :)

Keep posting!
_.

User avatar
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker » Mon Nov 29, 2004 8:54 pm

Hi, :-? can anyone tell me how to escape from P.E. in this problem.
I have tried a lot of things, still P.E. I got 6 P.E. for this problems

here is the things i have tried-

considering multiple cases, i printed one blank line after each case. then i
tried except the last case. i also tried %3d for the srl. no. and also " %d"
and all the combinations of these. and i ensure that my other printf are
ok , i copied then from the problem descripton......

thanks......
Jalal : AIUB SPARKS

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Post by _.B._ » Wed Jan 12, 2005 6:20 am

Greetings!
Did you try the I/O posted above?
_.

Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
Location: Bangladesh

630

Post by Sakib » Thu Sep 15, 2005 5:17 pm

i dont understand what is wrong.
please help me with some input output.
Here is my code.

Code: Select all

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

char ss[21],tt[21];
int i,j,k,n,m,p,q,r;

struct Texts
{
	char word[21];
	int len;
};
Texts text[2000];

//////////////////////////////////////////

void sort(char s[],int p)
{
	int i,j;
	char tmp;
	for(i=1;i<p;i++)
	{
		for(j=0;j<i;j++)
		{
			if(s[i]>s[j])
			{
				tmp=s[i];
				s[i]=s[j];
				s[j]=tmp;
			}
		}
	}
}

int isSame(char s[],int p,char t[],int q)
{
	int i;
	char t1[21],t2[21];
	if(p!=q)return 0;
	for(i=0;i<p;i++){t1[i]=s[i];}
	for(i=0;i<q;i++){t2[i]=t[i];}
	sort(t1,p);
	sort(t2,q);
	for(i=0;i<p;i++)
	{
		if(t1[i]!=t2[i])return 0;
	}
	return 1;
}


//////////////////////////////////////////

void main()
{
/////////////////////////////////
	while(scanf("%d\n",&n)==1)
	{
	for(i=0;i<n;i++)
	{
		scanf("%s",tt);
		r=strlen(tt);
		for(j=0;j<r;j++)
		{
			text[i].word[j]=tt[j];
		}
		text[i].len = r;
	}
//////////////////////////////////

	while(scanf("%s",ss)==1)
	{
		r = strlen(ss);
		if(strcmp(ss,"END")==0)break;
		printf("Anagrams for: ");
		for(j=0;j<r;j++){printf("%c",ss[j]);}
		printf("\n");
		k=0;
		for(i=0;i<n;i++)
		{
			if(isSame(ss,r,text[i].word,text[i].len)==1)
			{
				k++;
				printf("%3d) ",k);
				for(j=0;j<text[i].len;j++)printf("%c",text[i].word[j]);
				printf("\n");
			}
		}
		if(k==0)
		{
			printf("No anagrams for: ");
			for(j=0;j<r;j++){printf("%c",ss[j]);}
			printf("\n");
		}
	}
	//printf("\n");
	}
////////////////////////////////////////////////
}
/* Sorry For Nothing */

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Sat Oct 01, 2005 12:47 pm

See the updated problem statement....
http://acm.uva.es/p/v6/630.html

Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
Location: Bangladesh

Post by Sakib » Sat Oct 01, 2005 6:06 pm

Thanks a lot!!!!!!!!
I am ACC now. :D
/* Sorry For Nothing */

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

Re: 630 - Anagrams (II)

Post by uDebug » Tue Mar 25, 2014 3:29 pm

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 6 (600-699)”