KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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.
Tags (comma-separated)
Save Edits
Cancel