From dbf7abb9ebde982fbdbabdba3912b350e41c8e8e Mon Sep 17 00:00:00 2001 From: sebi Date: Tue, 4 Mar 2025 09:37:04 +0100 Subject: [PATCH] E20 Ex 12 + 13 --- Exercises/E20_Lists/Exercise_12.cs | 9 ++++++- Exercises/E20_Lists/Exercise_13.cs | 43 +++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Exercises/E20_Lists/Exercise_12.cs b/Exercises/E20_Lists/Exercise_12.cs index 98208f2..dfd7992 100644 --- a/Exercises/E20_Lists/Exercise_12.cs +++ b/Exercises/E20_Lists/Exercise_12.cs @@ -25,8 +25,15 @@ namespace Exercises_C_Sharp.E20_Lists static List Meth(List lis, char c) { /*Code START*/ + List tempList = []; - return new List(); + foreach(var element in lis) + if(!element.Contains(c)) + tempList.Add(element); + + return tempList; + //ODER: + return lis.Where(k => !k.Contains(c)).ToList(); /*Code ENDE*/ } } diff --git a/Exercises/E20_Lists/Exercise_13.cs b/Exercises/E20_Lists/Exercise_13.cs index fc45fbf..fb98349 100644 --- a/Exercises/E20_Lists/Exercise_13.cs +++ b/Exercises/E20_Lists/Exercise_13.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections.Generic; +using Microsoft.VisualBasic; namespace Exercises_C_Sharp.E20_Lists { @@ -20,9 +21,49 @@ namespace Exercises_C_Sharp.E20_Lists static List Meth(List lis) { /*Code START*/ + var newList = MakeKehrwertList(lis); + newList.Sort(); + newList = MakeKehrwertList(newList); - return new List(); + return newList; + + //ODER: + lis.Sort((k, l) => MakeKehrwert(k).CompareTo(MakeKehrwert(l))); + return lis; + /*Code ENDE*/ } + static List MakeKehrwertList(List list) + { + List temp = []; + foreach(var element in list) + temp.Add(MakeKehrwert(element)); + return temp; + } + + static int MakeKehrwert(int i) + { + int res = 0; + i *= 10; + + while(i / 10 != 0) + { + i /= 10; + res *= 10; + res += i % 10; + } + + return res; + } + static int MakeKehrwertString(int i) + { + string newI = i.ToString(); + string temp = ""; + + for(int k = newI.Length - 1; k >= 0; k--) + temp += newI[k]; + + return Convert.ToInt32(temp); + } } } \ No newline at end of file