public static void callMaxChars() { //MaxChar.MaxCharsWithASCII("rwersfsdfsdfsdf"); //MaxChar.MaxCharsWithASCII("testtestttettssssssssssstest"); MaxChar.MaxCharsWithDictionary("testtestttettssssssssssstest"); }
public static bool Annagrams(string str1, string str2) { str1 = Regex.Replace(str1.ToLower(), "[^a-zA-Z0-9]+", "", RegexOptions.Compiled); str2 = Regex.Replace(str2.ToLower(), "[^a-zA-Z0-9]+", "", RegexOptions.Compiled); Dictionary<int, int> str1Dic = MaxChar.MaxCharsWithReturnDictionary(str1.ToLower()); Dictionary<int, int> str2Dic = MaxChar.MaxCharsWithReturnDictionary(str2.ToLower()); if (str1Dic.Count != str2Dic.Count) { Console.WriteLine("strings are not annagrams"); return false; } else { if (!(str1Dic.Keys.All(str2Dic.ContainsKey))) { Console.WriteLine("strings are not annagrams"); return false; } else { var dict3 = str2Dic.Where(entry => str1Dic[entry.Key] != entry.Value) .ToDictionary(entry => entry.Key, entry => entry.Value); if (dict3.Count > 0) { Console.WriteLine("strings are not annagrams"); return false; } else { Console.WriteLine("strings are annagrams"); return true; } } } }