Необходимо реализовать поиск наибольшего количества идущих подряд одинаковых символов. Например, пользователь вводит слова: «приключение» и «ключи». Повторяющийся символы ЮЧ. (Отблагодарю копеечкой)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace List_and_Corteg { internal class Program { public static string FindCommonSubstring(string str1, string str2) { string commonSubstring = ""; int maxLength = 0; for (int i = 0; i < str1.Length; i++) { for (int j = 0; j < str2.Length; j++) { int k = 0; while (i + k < str1.Length && j + k < str2.Length && str1[i + k] == str2[j + k]) { k++; } if (k > maxLength) { maxLength = k; commonSubstring = str1.Substring(i, k); } } } return commonSubstring; } static void Main(string[] args) { Console.WriteLine("Введите первое слово:"); string word1 = Console.ReadLine(); Console.WriteLine("Введите второе слово:"); string word2 = Console.ReadLine(); string commonSubstring = FindCommonSubstring(word1, word2); Console.WriteLine($"Наибольшая общая подстрока: {commonSubstring}"); Console.ReadKey(); } } } CSHARP using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace List_and_Corteg { internal class Program { public static string FindCommonSubstring(string str1, string str2) { string commonSubstring = ""; int maxLength = 0; for (int i = 0; i < str1.Length; i++) { for (int j = 0; j < str2.Length; j++) { int k = 0; while (i + k < str1.Length && j + k < str2.Length && str1[i + k] == str2[j + k]) { k++; } if (k > maxLength) { maxLength = k; commonSubstring = str1.Substring(i, k); } } } return commonSubstring; } static void Main(string[] args) { Console.WriteLine("Введите первое слово:"); string word1 = Console.ReadLine(); Console.WriteLine("Введите второе слово:"); string word2 = Console.ReadLine(); string commonSubstring = FindCommonSubstring(word1, word2); Console.WriteLine($"Наибольшая общая подстрока: {commonSubstring}"); Console.ReadKey(); } } }