From e790fb41beb9136caea6cd2bb29e8ae1932cba41 Mon Sep 17 00:00:00 2001 From: Dmytro Kyba Date: Mon, 29 Apr 2024 23:19:58 +0300 Subject: [PATCH] fixed the issues and rewrote some code kinda idk --- src/methods.cs | 51 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/methods.cs b/src/methods.cs index 020c7f0..575fce9 100644 --- a/src/methods.cs +++ b/src/methods.cs @@ -10,56 +10,59 @@ static double CountAverageScore(Student student) { char[] marks = student.Marks; double sum = 0; - double n = marks.Length; foreach (var c in marks) { - if (c == '-') - { - sum += 2; - } - else { sum += double.Parse(c.ToString()); } - + sum += (c == '-') ? 2 : double.Parse(c.ToString()); } - return sum / n; + return Math.Round(sum / 3, 1); } - foreach (var student in students) + + static IEnumerable FilterTalentedPhysicians(List students) { - if (student.Marks[1] == '5') - { - Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {CountAverageScore(student)} {student.scholarship}"); - } - }; + return students.Where(student => student.Marks[1] == '5'); + } + + foreach (var student in FilterTalentedPhysicians(students)) + { + Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {CountAverageScore(student):0.0} {student.scholarship}"); + } } - - static void Var24(List students) { + + static void Var24(List students) + { var summer_kids = FilterSummerKids(students); foreach (var (dude, avg) in summer_kids.Zip(EvalAverages(summer_kids))) Console.WriteLine($"{dude.surName} {dude.firstName} {avg:0.0}"); } - public static IEnumerable FilterSummerKids(List students) { - return students.Where(student => { + public static IEnumerable FilterSummerKids(List students) + { + return students.Where(student => + { if (DateTime.TryParseExact(student.dateOfBirth, "dd.MM.yyyy", null, System.Globalization.DateTimeStyles.None, out DateTime date) - ){ + ) + { return date.Month >= 6 && date.Month <= 8; } return false; }); } - public static List EvalAverages(IEnumerable? students) { + public static List EvalAverages(IEnumerable? students) + { List averages = []; - if (students != null) { - foreach (var dude in students) { + if (students != null) + { + foreach (var dude in students) + { int sum = 0; for (int i = 0; i < 3; i++) sum += (dude.Marks[i] == '-') ? 2 : dude.Marks[i] - '0'; averages.Add(sum / 3.0); - } + } } return averages; } } } -