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

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

Well...

Post by _.B._ »

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 »

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 :-)
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Maybe this.

Post by _.B._ »

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 »

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:
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Good!

Post by _.B._ »

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

Keep posting!
_.
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker »

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
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Post by _.B._ »

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 »

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 */
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 »

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 »

Thanks a lot!!!!!!!!
I am ACC now. :D
/* Sorry For Nothing */
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 630 - Anagrams (II)

Post by uDebug »

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