/
hahahihi
/
csharpTasks
Обзор
Документация
Войти
/
hahahihi
/
csharpTasks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
csharp/lines.cs
90 строк
3 KB
belovAndrey
update csharp/lines.cs
25 окт 2025, 22:06
25 окт 2025, 22:06
2ee53dc
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Text; namespace TextAnalysis { static class SentencesParserTask { public static List<List<string>> ParseSentences(string text) { if (text == null || text.Length == 0) return new List<List<string>>(); var result = new List<List<string>>(); var currentWord = new StringBuilder(); var currentSentence = new List<string>(); ParseCharacters(text, result, currentWord, currentSentence); HandleTrailingContent(result, currentWord, currentSentence); return result; } private static void ParseCharacters( string text; List<List<string>> result, StringBuilder currentWord, List<string> currentSentence) { for (int i = 0; i < text.Length; i++) { char ch = text[i]; if (IsPartOfWord(ch)) { currentWord.Append(char.ToLower(ch)); } else { FlushWord(currentWord, currentSentence); if (IsSentenceDelimiter(ch)) { FlushSentence(currentSentence, result); } } } } private static bool IsPartOfWord(char ch) { return char.IsLetter(ch) || ch == '\''; } private static bool IsSentenceDelimiter(char ch) { return ch == '.' || ch == '!' || ch == '?' || ch == ';' || ch == ':' || ch == '(' || ch == ')'; } private static void FlushWord(StringBuilder wordBuffer, List<string> sentence) { if (wordBuffer.Length > 0) { sentence.Add(wordBuffer.ToString()); wordBuffer.Clear(); } } private static void FlushSentence(List<string> sentence, List<List<string>> result) { if (sentence.Count > 0) { result.Add(new List<string>(sentence)); sentence.Clear(); } } private static void HandleTrailingContent( List<List<string>> result, StringBuilder currentWord, List<string> currentSentence) { FlushWord(currentWord, currentSentence); if (currentSentence.Count > 0) { result.Add(currentSentence); } } } }