The anagram algorithm is a simple algorithm. Create a function where you compare two strings and check if they are anagrams of each other. The strings can contain any type of characters like “Hi, there!” and “There…
Given a set of words, we need to find the anagram words and display each category alone using the best algorithm.
input:
man car kile arc none like
output:
man
car arc
kile like
none
The best solution I am developing now is based on an hashtable, but I am thinking about equation to convert anagram word into integer value.
Example: man => 'm'+'a'+'n' but this will not give unique values.
Any suggestion?
See following code in C#:
string line = Console.ReadLine();
string []words=line.Split(' ');
int[] numbers = GetUniqueInts(words);
for (int i = 0; i < words.Length; i++)
{
if (table.ContainsKey(numbers[i]))
{
table[numbers[i]] = table[numbers[i]].Append(words[i]);
}
else
{
table.Add(numbers[i],new StringBuilder(words[i]));
}
}
The problem is how to develop GetUniqueInts(string [])
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With