Поиск одинаковых букв в строке - C#
Формулировка задачи:
Всем привет.
Можете помочь, нужно в строке со словами через запятую найти наиболее чаще встречающееся сочетание трех соседних букв в слове и их количество в строке
Решение задачи: «Поиск одинаковых букв в строке»
textual
Листинг программы
private static void Main()
{
string words = "hello,hi,hahaha,ohohoh,ihihi,apapapapa" ;
string[] split = words.Split(new string[] {","},StringSplitOptions.RemoveEmptyEntries);
List<string> parts = new List<string>();
int times = 0;
Dictionary<string,int> vacabular = new Dictionary<string,int>();
for(int i = 0; i < split.Length; i++)
{
if (split[i].Length < 3)
continue;
for (int j = 0; j < split[i].Length - 2; j++)
parts.Add(split[i].Substring(j, 3));
for (int j = 0; j < parts.Count; j++)
{
for (int count = 0; count < parts.Count; count++)
if (parts[j].Contains(parts[count]))
{
times++;
}
if (vacabular.ContainsKey(parts[j]))
{
int key = 1;
if (vacabular.TryGetValue(parts[j], out key))
if (times > key)
vacabular.Remove(parts[j]);
}
else
vacabular.Add(parts[j], times);
times = 0;
}
}
}