Cawa245

Untitled

May 7th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. public static void LinqObj11(Client[] clients)
  2. {
  3. var allData = clients
  4. .GroupBy(client => (year: client.Year, mounth: client.Mounth)) //группируем по паре-"год-месяц"
  5. .Select(z =>
  6. Tuple.Create(
  7. z.Key,
  8. z.Select(x => x.Duration).Sum()
  9. )
  10. )
  11. .OrderBy(z => z.Item2) //сортирует по возрастанию общей продолжительности
  12. .ThenByDescending(z => z.Item1.year) //если одинаковая продолжительность, по убыванию года
  13. .ThenBy(z => z.Item1.mounth); //если одинаковый год, по возрастанию месяца
  14.  
  15. foreach (var ((year, mounth), time) in allData)
  16. Console.WriteLine($"Год {year}. Месяц {mounth}. Общее время занятий {time}.");
  17. }
  18.  
  19. public class Client
  20. {
  21. public Client(long id, int year, int mounth, long duration)
  22. {
  23. Id = id;
  24. Year = year;
  25. Mounth = mounth;
  26. Duration = duration;
  27. }
  28.  
  29. public long Id;
  30. public int Year;
  31. public int Mounth;
  32. public long Duration;
  33. }
  34.  
  35. public static void LinqObj61(Student[] students)
  36. {
  37. var temp2 = students
  38. .GroupBy(student => (student.LastName, student.Initials))
  39. .Select(z =>
  40. Tuple.Create(z.Key.Item1, z.Key.Item2,
  41. z.GroupBy(x => x.ItemName)
  42. .Select(c =>
  43. Tuple.Create(
  44. c.Key,
  45. c.Select(x => x.Mark)
  46. .Sum() / (double) c.Count())
  47. )
  48. )
  49. )
  50. .OrderBy(z => (z.Item1, z.Item2));
  51.  
  52.  
  53. foreach (var (lastName, inicials, studyInfo) in temp2)
  54. {
  55. var list = new List<string>
  56. {
  57. "Alghebra",
  58. "Informatics",
  59. "Geometry"
  60. };
  61. foreach (var (item, avgMarks) in studyInfo)
  62. {
  63. list.Remove(item);
  64. Console.Write($"Фамилия {lastName}. Инициалы {inicials}. Предмет {item}. Средняя оценка ");
  65. Console.WriteLine("{0:0.00}", avgMarks);
  66. }
  67.  
  68. //отдельный вывод предметов без оценок
  69. list.ForEach(x =>
  70. {
  71. Console.WriteLine(
  72. $"Фамилия {lastName}. Инициалы {inicials}. Предмет {x}. Средняя оценка 0.00");
  73. });
  74. }
  75. }
  76.  
  77. public class Student
  78. {
  79. public Student(string lastName, string initials, int clas, string itemName, int mark)
  80. {
  81. LastName = lastName;
  82. Initials = initials;
  83. Class = clas;
  84. ItemName = itemName;
  85. Mark = mark;
  86. }
  87.  
  88. public string LastName;
  89. public string Initials;
  90. public int Class;
  91. public string ItemName;
  92. public int Mark;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment