156 - Ananagrams
Moderator: Board moderators
-
- New poster
- Posts: 4
- Joined: Thu Feb 03, 2005 9:16 pm
- Location: chennai
- Contact:
sorry i don't know your program..
sorry i don't know your program..
sorry.sorry.sorry.sorry.sorry.
sorry.sorry.sorry.sorry.sorry.
-
- New poster
- Posts: 4
- Joined: Thu Jul 08, 2004 12:53 pm
- Contact:
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
sridhar
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
sridhar
-
- New poster
- Posts: 4
- Joined: Thu Jul 08, 2004 12:53 pm
- Contact:
thanks a lot for the reply. Can you please send the input/output to the mailid anala.sridhar@gmail.com .
thanks again
sridhar
thanks again
sridhar
Hello,
Can I read the input for this problem this way?
If no, why? Thanks.
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++;
}
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
Thanks, did works and I got AC!
For those who want help, my ACed code outputs:
For those who want help, my ACed code outputs:
hop it helpsbeloni@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$
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
Getting RE plz Help
hi ...
i m getting RE for this program....
cant find out why..
Can anyone help plz...
here is my code.........
plz help
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;
}
-
- New poster
- Posts: 2
- Joined: Fri Oct 05, 2012 12:12 am
156 Ananagram WA? WHY?
DELETED!
Last edited by Burhanuddin on Fri Oct 05, 2012 10:42 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 156 Ananagram WA? WHY?
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!
-
- New poster
- Posts: 2
- Joined: Fri Oct 05, 2012 12:12 am
Re: 156 Ananagram WA? WHY?
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!
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!
Re: 156 Ananagram WA? WHY?
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.
Got AC, thanks, funny thing is the compiler pointed that out but I usually ignore the compiler warnings.
but it runs fine on my pc so I can't find the error. All advice and criticism appreciated, thx.
Code: Select all
removed
Last edited by IanSwartz on Sat Sep 21, 2013 11:11 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 156 Ananagram WA? WHY?
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!