/
dashytka
/
Practice-Auto-completion
Обзор
Документация
Войти
/
dashytka
/
Practice-Auto-completion
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
c
72 строки
2 KB
dashytka
create c#
21 ноя 2025, 21:45
21 ноя 2025, 21:45
8006888
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using NUnit.Framework; namespace Autocomplete { internal class AutocompleteTask { public static string FindFirstByPrefix( IReadOnlyList<string> phrases, string prefix) { var leftBorder = LeftBorderTask.GetLeftBorderIndex( phrases, prefix, -1, phrases.Count); var firstIndex = leftBorder + 1; if (firstIndex < phrases.Count && phrases[firstIndex].StartsWith( prefix, StringComparison.OrdinalIgnoreCase)) return phrases[firstIndex]; return null; } public static string[] GetTopByPrefix( IReadOnlyList<string> phrases, string prefix, int count) { var leftBorder = LeftBorderTask.GetLeftBorderIndex( phrases, prefix, -1, phrases.Count) + 1; var phrasesCount = GetCountByPrefix(phrases, prefix); if (phrasesCount <= 0) return new string[0]; var actualCount = Math.Min(count, phrasesCount); var topPhrases = new string[actualCount]; for (var i = 0; i < actualCount; i++) topPhrases[i] = phrases[leftBorder + i]; return topPhrases; } public static int GetCountByPrefix( IReadOnlyList<string> phrases, string prefix) { var leftBorder = LeftBorderTask.GetLeftBorderIndex( phrases, prefix, -1, phrases.Count); var rightBorder = RightBorderTask.GetRightBorderIndex( phrases, prefix, -1, phrases.Count); return rightBorder - leftBorder - 1; } } [TestFixture] public class AutocompleteTests { [Test] public void TopByPrefix_IsEmpty_WhenNoPhrases() { } [Test] public void CountByPrefix_IsTotalCount_WhenEmptyPrefix() { } } }