From 66b05d63c21fc2406c2c9e092b31410446cefd54 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 25 Nov 2021 23:57:59 +0200 Subject: [PATCH] fix: simplify "FindWord1Line" --- Lab4.K2/Program.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Lab4.K2/Program.cs b/Lab4.K2/Program.cs index 6c41ff2..607ba5b 100644 --- a/Lab4.K2/Program.cs +++ b/Lab4.K2/Program.cs @@ -35,23 +35,13 @@ namespace Lab4.K2 public static string FindWord1Line(string line, string punctuation) { - List wordsWith3Vowels = new List(); - + Match longestWord = null; foreach (Match match in MatchByWords(line, punctuation)) { int vowelCount = NumberDifferentVowelsInLine(match.Value); - if (vowelCount == 3) + if (vowelCount == 3 && (longestWord == null || longestWord.Groups[1].Length < match.Groups[1].Length)) { - wordsWith3Vowels.Add(match); - } - } - - Match longestWord = null; - foreach (Match word in wordsWith3Vowels) - { - if (word.Groups[1].Length > longestWord.Groups[1].Length) - { - longestWord = word; + longestWord = match; } }