diff --git a/fordulo_1/Program/Program.cs b/fordulo_1/Program/Program.cs index 44a5295..a279541 100644 --- a/fordulo_1/Program/Program.cs +++ b/fordulo_1/Program/Program.cs @@ -84,7 +84,8 @@ public static class Karakterek return count; } - public static int TotalDistanceTraveled(string input){ + public static int TotalDistanceTraveled(string input) + { int x = 0; int y = 0; @@ -111,7 +112,8 @@ public static class Karakterek } } -public static class Szoveg{ +public static class Szoveg +{ public static List<string> fullTextInListOfString = new List<string>(); public static List<string> wordsWithUniqeCharactersOnly = new List<string>(); @@ -151,129 +153,167 @@ public static class Szoveg{ public static int GreatestDistanceBetweenWords(string input) { int maxDistance = 0; - int? firstIndex = null; - + int firstEndIndex = 0; - int? secondIndex = null; + int secondStartIndex = 0; int secondEndIndex = 0; for (int i = 1; i < input.Length - 2; i++) { // új névelő megtalálva - if (input[i] == 'A' && input[i - 1] == ' ' && input[i + 1] == ' ') + if (input[i] == 'A' && input[i - 1] == ' ' && input[i + 1] == ' ') { - if (firstIndex == null) + if (firstEndIndex == 0) { - firstIndex = i; firstEndIndex = i; continue; } - if (secondIndex == null && firstIndex != null) + if (secondEndIndex == 0 && firstEndIndex != 0) { - secondIndex = i; secondStartIndex = i; secondEndIndex = i; } // kettő közötti távolság int distance = Convert.ToInt32(secondStartIndex - firstEndIndex - 1); - if (distance > maxDistance) + if (distance > maxDistance) { maxDistance = distance; } - firstIndex = secondIndex; - + firstEndIndex = secondEndIndex; - secondIndex = i; secondStartIndex = i; secondEndIndex = i; continue; } - if (input [i] == 'A' && input[i + 1] == 'Z' && input[i - 1] == ' ' && input[i + 2] == ' '){ - if (firstIndex == null) + if (input[i] == 'A' && input[i + 1] == 'Z' && input[i - 1] == ' ' && input[i + 2] == ' ') + { + if (firstEndIndex == 0) { - firstIndex = i; - firstEndIndex = i + 1; + firstEndIndex = i; continue; } - if (secondIndex == null && firstIndex != null) + if (secondEndIndex == 0 && firstEndIndex != 0) { - secondIndex = i; secondStartIndex = i; secondEndIndex = i + 1; } // kettő közötti távolság int distance = Convert.ToInt32(secondStartIndex - firstEndIndex - 1); - if (distance > maxDistance) + if (distance > maxDistance) { maxDistance = distance; } - firstIndex = secondIndex; - firstEndIndex = secondEndIndex; - - secondIndex = i; + secondStartIndex = i; secondEndIndex = i + 1; } } - + return maxDistance; } + + public static int MaxDistanceBetweenArticles(string text) + { + List<int> distances = new List<int>(); + Regex regex = new Regex(@"\b(AZ|A)\b", RegexOptions.IgnoreCase); + + foreach (Match match in regex.Matches(text)) + { + int startPosition = match.Index; + int endPosition = match.Index + match.Length - 1; + + var asd = match.NextMatch(); + var nextStart = asd.Index; + var nextEnd = asd.Index + asd.Length - 1; + + distances.Add(nextStart - endPosition - 1); + } + + + return distances.Max(); // Max distance + } + + public static int UniquePalindromes() + { + List<string> palindromes = new List<string>(); + + foreach (var word in fullTextInListOfString) + { + if (word.Length < 2) + { + continue; + } + + if (word == new string(word.Reverse().ToArray())) + { + if (!palindromes.Contains(word)) + { + palindromes.Add(word); + } + } + } + return palindromes.Count; + } } - public class Program +public class Program +{ + public static void Main(string[] args) { - public static void Main(string[] args) - { - Karakterek.ReadDataFromFile(@"..\karsor.txt"); + Karakterek.ReadDataFromFile(@"..\karsor.txt"); - //System.Console.WriteLine($"{Karakterek.KarakterekList.Count}"); + //System.Console.WriteLine($"{Karakterek.KarakterekList.Count}"); - // feladat 1 a - /* - var longestStringWithTwoCharactersOnly = Karakterek.LongestStringWithTwoCharactersOnly(); - var karakterek = longestStringWithTwoCharactersOnly.Distinct().OrderBy(c => c).ToArray(); - int longestStringWithTwoCharactersOnlyLength = longestStringWithTwoCharactersOnly.Count; + // feladat 1 a + /* + var longestStringWithTwoCharactersOnly = Karakterek.LongestStringWithTwoCharactersOnly(); + var karakterek = longestStringWithTwoCharactersOnly.Distinct().OrderBy(c => c).ToArray(); + int longestStringWithTwoCharactersOnlyLength = longestStringWithTwoCharactersOnly.Count; - System.Console.WriteLine($"{karakterek[0]}{karakterek[1]}{longestStringWithTwoCharactersOnlyLength}"); - */ + System.Console.WriteLine($"{karakterek[0]}{karakterek[1]}{longestStringWithTwoCharactersOnlyLength}"); + */ - // feladat 1 b - - // ez az input változó volt használva a b és a c részben is - //string input = new string(Karakterek.KarakterekList.ToArray()); + // feladat 1 b - //System.Console.WriteLine($"{Karakterek.CountABCSequences(input)}"); + // ez az input változó volt használva a b és a c részben is + //string input = new string(Karakterek.KarakterekList.ToArray()); - // feladat 1 c - //System.Console.WriteLine($"{Karakterek.TotalDistanceTraveled(input)}"); + //System.Console.WriteLine($"{Karakterek.CountABCSequences(input)}"); - // feladat 2 a + // feladat 1 c + //System.Console.WriteLine($"{Karakterek.TotalDistanceTraveled(input)}"); - Szoveg.ReadDataFromFile(@"..\testinput.txt"); + // feladat 2 a - /* - Szoveg.wordsWithUniqeCharactersOnly = Szoveg.WordsWithUniqeCharactersOnly(); + Szoveg.ReadDataFromFile(@"..\szoveg.txt"); - System.Console.WriteLine($"{Szoveg.LongestStringWithUniqueCharacters()}"); - */ + /* + Szoveg.wordsWithUniqeCharactersOnly = Szoveg.WordsWithUniqeCharactersOnly(); - // feladat 2 b - string fullTextInSingleString = string.Join(" ", Szoveg.fullTextInListOfString); + System.Console.WriteLine($"{Szoveg.LongestStringWithUniqueCharacters()}"); + */ - int value = Szoveg.GreatestDistanceBetweenWords(fullTextInSingleString); + // feladat 2 b + string fullTextInSingleString = string.Join(" ", Szoveg.fullTextInListOfString); - System.Console.WriteLine($"{value}"); + //int value = Szoveg.GreatestDistanceBetweenWords(fullTextInSingleString); - } - } \ No newline at end of file + int value = Szoveg.MaxDistanceBetweenArticles(fullTextInSingleString); + + System.Console.WriteLine($"{value}"); + + System.Console.WriteLine($"{Szoveg.UniquePalindromes()}"); + + } +} \ No newline at end of file diff --git a/fordulo_1/Program/bin/Debug/net9.0/Program.dll b/fordulo_1/Program/bin/Debug/net9.0/Program.dll index 8b1f759..cda61db 100644 Binary files a/fordulo_1/Program/bin/Debug/net9.0/Program.dll and b/fordulo_1/Program/bin/Debug/net9.0/Program.dll differ diff --git a/fordulo_1/Program/bin/Debug/net9.0/Program.exe b/fordulo_1/Program/bin/Debug/net9.0/Program.exe index a41c019..d8a8fa7 100644 Binary files a/fordulo_1/Program/bin/Debug/net9.0/Program.exe and b/fordulo_1/Program/bin/Debug/net9.0/Program.exe differ diff --git a/fordulo_1/Program/bin/Debug/net9.0/Program.pdb b/fordulo_1/Program/bin/Debug/net9.0/Program.pdb index c500acd..18d0811 100644 Binary files a/fordulo_1/Program/bin/Debug/net9.0/Program.pdb and b/fordulo_1/Program/bin/Debug/net9.0/Program.pdb differ diff --git a/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfo.cs b/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfo.cs index 92f7b30..a7178f2 100644 --- a/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfo.cs +++ b/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Program")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2d3a3b5498848de0502de226cf3680344b851fa3")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4370f4cd05125a6cf533b209e139477f99b353dd")] [assembly: System.Reflection.AssemblyProductAttribute("Program")] [assembly: System.Reflection.AssemblyTitleAttribute("Program")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfoInputs.cache b/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfoInputs.cache index ed0375e..0579ba8 100644 --- a/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfoInputs.cache +++ b/fordulo_1/Program/obj/Debug/net9.0/Program.AssemblyInfoInputs.cache @@ -1 +1 @@ -5f0e7be5aed498aebc515a122ed65f513d902cc336ac583393b795272d573e2f +73ebb59b91d6ddf6e8dd33d5b30abd9efdedbeb154e4bd540e805b4ea0fe83ff diff --git a/fordulo_1/Program/obj/Debug/net9.0/Program.dll b/fordulo_1/Program/obj/Debug/net9.0/Program.dll index 8b1f759..cda61db 100644 Binary files a/fordulo_1/Program/obj/Debug/net9.0/Program.dll and b/fordulo_1/Program/obj/Debug/net9.0/Program.dll differ diff --git a/fordulo_1/Program/obj/Debug/net9.0/Program.pdb b/fordulo_1/Program/obj/Debug/net9.0/Program.pdb index c500acd..18d0811 100644 Binary files a/fordulo_1/Program/obj/Debug/net9.0/Program.pdb and b/fordulo_1/Program/obj/Debug/net9.0/Program.pdb differ diff --git a/fordulo_1/Program/obj/Debug/net9.0/apphost.exe b/fordulo_1/Program/obj/Debug/net9.0/apphost.exe index a41c019..d8a8fa7 100644 Binary files a/fordulo_1/Program/obj/Debug/net9.0/apphost.exe and b/fordulo_1/Program/obj/Debug/net9.0/apphost.exe differ diff --git a/fordulo_1/Program/obj/Debug/net9.0/ref/Program.dll b/fordulo_1/Program/obj/Debug/net9.0/ref/Program.dll index a6d1169..4f0b9bd 100644 Binary files a/fordulo_1/Program/obj/Debug/net9.0/ref/Program.dll and b/fordulo_1/Program/obj/Debug/net9.0/ref/Program.dll differ diff --git a/fordulo_1/Program/obj/Debug/net9.0/refint/Program.dll b/fordulo_1/Program/obj/Debug/net9.0/refint/Program.dll index a6d1169..4f0b9bd 100644 Binary files a/fordulo_1/Program/obj/Debug/net9.0/refint/Program.dll and b/fordulo_1/Program/obj/Debug/net9.0/refint/Program.dll differ diff --git a/fordulo_1/testinput.txt b/fordulo_1/testinput.txt index fb6a9fb..58e56c2 100644 --- a/fordulo_1/testinput.txt +++ b/fordulo_1/testinput.txt @@ -1,2 +1,2 @@ -HOL TEREM A M A GYAR VITEZ - AZ PATAKBAN KET GYERMEK FURDIK \ No newline at end of file +HOL TEREM A MAGYAR VITEZ +A PATAKBAN KET GYERMEK FURDIK \ No newline at end of file diff --git a/images/feladat3.png b/images/feladat3.png new file mode 100644 index 0000000..7ab4309 Binary files /dev/null and b/images/feladat3.png differ diff --git a/megoldasok.md b/megoldasok.md index 815009a..db53cb4 100644 --- a/megoldasok.md +++ b/megoldasok.md @@ -9,10 +9,11 @@ ### 2. feladat - a: `MEGFORDULTAK` -- b: `` -- c: `` +- b: `322` +- c: `20` ### 3. feladat - a: `7` -- b: `` -- c: `` \ No newline at end of file +- b: `78` +  +- c: `53` \ No newline at end of file