156 - Ananagrams

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

Moderator: Board moderators

Ankur Kumar Nayak
New poster
Posts: 4
Joined: Thu Feb 03, 2005 9:16 pm
Location: chennai
Contact:

Post by Ankur Kumar Nayak »

Sorry for troubling.....Got my code accepted finally....just a minor bug....
If at first you don't succeed.....you are a programmer

sds1100
Learning poster
Posts: 95
Joined: Sat Dec 10, 2005 2:09 pm

sorry i don't know your program..

Post by sds1100 »

sorry i don't know your program..
sorry.sorry.sorry.sorry.sorry.

anala_sridhar
New poster
Posts: 4
Joined: Thu Jul 08, 2004 12:53 pm
Contact:

Post by anala_sridhar »

i have tried with Farid Ahmadov's test input (above) and got the same output but still got the code rejected (WA) in Java.


can someone please help me with more sample input texts.

according to the problem statement, single characters ARE Ananagrams.
In that case, what should be the output for the
Input
  • A a a A
    B b B
    C c
thanks in adv
sridhar

rickyliu
New poster
Posts: 30
Joined: Thu Sep 28, 2006 7:16 am

Post by rickyliu »

anala_sridhar, I can send you the input/output if you provide a email address. Single letter words are relative anangrams but the input used by the judge seems not to have such cases. My AC program does not print out anything from your input.

anala_sridhar
New poster
Posts: 4
Joined: Thu Jul 08, 2004 12:53 pm
Contact:

Post by anala_sridhar »

thanks a lot for the reply. Can you please send the input/output to the mailid anala.sridhar@gmail.com .

thanks again
sridhar

rickyliu
New poster
Posts: 30
Joined: Thu Sep 28, 2006 7:16 am

Post by rickyliu »

Please check your mail box.

beloni
Learning poster
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

Post by beloni »

Hello,

Can I read the input for this problem this way?

Code: Select all

char dic[MAX_DIC][MAX_DIC];
while(true)
	{
		cin >> dic[i];
		if( dic[i][0] == '#' )
			break;
		else
			i++;
	}
If no, why? Thanks.
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

Post by ranban282 »

I think you can.

beloni
Learning poster
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

Post by beloni »

Thanks, did works and I got AC!
For those who want help, my ACed code outputs:
beloni@hopcroft:~/programming/judge/ananagram_156_0$ cat ananagram.in2
A a a A a a B B B C Hello HELLO Hi REpLy
ladder came tape soon leader acme RIDE lone Dreis peat
ScAlE orb eye Rides dealer NotE derail LaCeS drIed
noel dire Disk mace Rob dries
#
beloni@hopcroft:~/programming/judge/ananagram_156_0$ ./ananagram < ananagram.in2
C
Disk
Hi
NotE
REpLy
derail
drIed
eye
ladder
soon
beloni@hopcroft:~/programming/judge/ananagram_156_0$
hop it helps
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor

ata
New poster
Posts: 2
Joined: Wed Nov 07, 2007 5:54 pm
Location: BANGLADESH

Getting RE plz Help

Post by ata »

hi ...
i m getting RE for this program....
cant find out why..
Can anyone help plz...

here is my code.........

Code: Select all


#include<stdio.h>
#include<string.h>
int str[26];
char result[1001][25];

int is_ana(char c[],char d[])
{
	char e[25],b[25];
	int i,j,k;

	strcpy(e,c);
	strcpy(b,d);
	if(strlen(e)!=strlen(b))
	return 0;
	
	for(i=0;i<26;i++)
		str[i]=0;
	
	for(k=0;k<strlen(e);k++)
	{
		if(e[k]>='A' && e[k]<='Z')
			e[k]='a'+e[k]-'A';
	}
	
	for(k=0;k<strlen(b);k++)
	{
		if(b[k]>='A' && b[k]<='Z')
			b[k]='a'+b[k]-'A';
	}

	for(j=0;j<strlen(e);j++)
	{
		i=e[j]-'a';
		str[i]=str[i]+1;
	}
	
	for(j=0;j<strlen(b);j++)
	{
		i=b[j]-'a';
		str[i]=str[i]-1;
	}
	i=0;
	while(i<26)
	{
		if(str[i]==0)
			i++;
		else
			return 0;
	}
	return 1;

}

int main()
{
	char a[1001][25];
	char temp[25];
	int i,j,l,flag,x;
	i=0;
	while(scanf("%s",temp)==1)
	{
		if(strcmp(temp,"#")==0)
			break;
	
		strcpy(a[i],temp);
			i++;
	}
	x=0;
	for(j=0;j<i;j++)
	{
		if(strcmp(a[j],"0")==0)
			continue;
		flag=0;
	
		for(l=0;l<i;l++)
		{
		
			if(j==l || (!strcmp(a[j],"0")))
				continue;
			if(is_ana(a[j],a[l])==1)
			{
				strcpy(a[l],"0");
				flag=1;
				
			}
		}
		
		if(flag==0)
		{
			strcpy(result[x],a[j]);
			x++;
		}
			
	}

	for(i=0;i<x-1;i++)
		for(j=i+1;j<x;j++)
		{
			if(strcmp(result[i],result[j])>0)
			{
				strcpy(temp,result[j]);
				strcpy(result[j],result[i]);
				strcpy(result[i],temp);
			}
		}

	for(i=0;i<x;i++)
		printf("%s\n",result[i]);
	return 0;
}
plz help

Burhanuddin
New poster
Posts: 2
Joined: Fri Oct 05, 2012 12:12 am

156 Ananagram WA? WHY?

Post by Burhanuddin »

DELETED!
Last edited by Burhanuddin on Fri Oct 05, 2012 10:42 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 156 Ananagram WA? WHY?

Post by brianfry713 »

Print a newline at the end of the last line. You'll still get WA after fixing that. Try reading a string at a time instead of a char at a time. When I test your code on my system I get a newline at the start of the output for the input:

Code: Select all

a
#
Check input and AC output for thousands of problems on uDebug!

Burhanuddin
New poster
Posts: 2
Joined: Fri Oct 05, 2012 12:12 am

Re: 156 Ananagram WA? WHY?

Post by Burhanuddin »

Actually I was printing a new line after the output, but then I thought that was the problem.
Anyways you are correct, the problem was that it was printing a new line at the beginning of the output for some inputs. I corrected that by checking the size of the char vector. So now its AC!
Thanks for that input!

IanSwartz
New poster
Posts: 6
Joined: Wed Sep 18, 2013 11:44 am

Re: 156 Ananagram WA? WHY?

Post by IanSwartz »

Hi, getting RTE, possibly due to erasing elements in the vector and iterating through it at the same time,
but it runs fine on my pc so I can't find the error. All advice and criticism appreciated, thx.

Code: Select all

removed
Got AC, thanks, funny thing is the compiler pointed that out but I usually ignore the compiler warnings.
Last edited by IanSwartz on Sat Sep 21, 2013 11:11 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 156 Ananagram WA? WHY?

Post by brianfry713 »

Change this function to:

Code: Select all

bool myVSort(string lhs, string rhs)
{
    return (lhs<rhs);
}
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 1 (100-199)”