You are given a dictionary of words, and a string as an input. The given string is an anagram of one or more words in the dictionary. Find all such words
int j = 0;
char *a[]= {
"satm",
"mats",
"tams",
"tasm",
"satish",
"rajesh"
};
int main()
{
/* print the words in the dictionary*/
while((*(a + j)) != NULL)
{
printf("%s\n",*(a+j));
j++ ;
}
int N;
char str[50];
int i;
printf("enter the string\n");
scanf("%s",str);
N = strlen(str);
printf("the string length is : %d\n",N);
Permute(str,0,N);
if(count == 0)
printf("match not found\n");
return 0;
}
/*==================================
Function Permute
==================================*/
void Permute(char v[],int start, int n)
{
search(a,v);
if (start=start; i--)
{
for(j=i+1; j
Write a function to solve anagrams
I guest best algorithm would be -
short the alphabets in each strings.
If any two strings are anagram, the sorting results out to be the same same string.
eg. EAT, and ATE both are anagram.
because if you sort the alphabets, both yield to AET.
Hope this would help.
i hope this is rite!!
// i worked in GCC compiler and i am getting it rite...
#include
#include
static int count = 0 ;
//Function declarations
void Permute(char [],int,int);
void Swap(char [],int,int);
void Rotate_Left(char v[],int,int);
void search(char ** , char *);
int j = 0;
char *a[]= {
"satm",
"mats",
"tams",
"tasm",
"satish",
"rajesh"
};
int main()
{
/* print the words in the dictionary*/
while((*(a + j)) != NULL)
{
printf("%s\n",*(a+j));
j++ ;
}
int N;
char str[50];
int i;
printf("enter the string\n");
scanf("%s",str);
N = strlen(str);
printf("the string length is : %d\n",N);
Permute(str,0,N);
if(count == 0)
printf("match not found\n");
return 0;
}
/*==================================
Function Permute
==================================*/
void Permute(char v[],int start, int n)
{
search(a,v);
if (start=start; i--)
{
for(j=i+1; j
Write a function to solve anagrams
record the frequencies of letters of the input sring in a ineger array.
then match it with each of the dictionary words. I think this one if faster than checking for all possible permutation, huh?