Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void LinqObj11(Client[] clients)
- {
- var allData = clients
- .GroupBy(client => (year: client.Year, mounth: client.Mounth)) //группируем по паре-"год-месяц"
- .Select(z =>
- Tuple.Create(
- z.Key,
- z.Select(x => x.Duration).Sum()
- )
- )
- .OrderBy(z => z.Item2) //сортирует по возрастанию общей продолжительности
- .ThenByDescending(z => z.Item1.year) //если одинаковая продолжительность, по убыванию года
- .ThenBy(z => z.Item1.mounth); //если одинаковый год, по возрастанию месяца
- foreach (var ((year, mounth), time) in allData)
- Console.WriteLine($"Год {year}. Месяц {mounth}. Общее время занятий {time}.");
- }
- public class Client
- {
- public Client(long id, int year, int mounth, long duration)
- {
- Id = id;
- Year = year;
- Mounth = mounth;
- Duration = duration;
- }
- public long Id;
- public int Year;
- public int Mounth;
- public long Duration;
- }
- public static void LinqObj61(Student[] students)
- {
- var temp2 = students
- .GroupBy(student => (student.LastName, student.Initials))
- .Select(z =>
- Tuple.Create(z.Key.Item1, z.Key.Item2,
- z.GroupBy(x => x.ItemName)
- .Select(c =>
- Tuple.Create(
- c.Key,
- c.Select(x => x.Mark)
- .Sum() / (double) c.Count())
- )
- )
- )
- .OrderBy(z => (z.Item1, z.Item2));
- foreach (var (lastName, inicials, studyInfo) in temp2)
- {
- var list = new List<string>
- {
- "Alghebra",
- "Informatics",
- "Geometry"
- };
- foreach (var (item, avgMarks) in studyInfo)
- {
- list.Remove(item);
- Console.Write($"Фамилия {lastName}. Инициалы {inicials}. Предмет {item}. Средняя оценка ");
- Console.WriteLine("{0:0.00}", avgMarks);
- }
- //отдельный вывод предметов без оценок
- list.ForEach(x =>
- {
- Console.WriteLine(
- $"Фамилия {lastName}. Инициалы {inicials}. Предмет {x}. Средняя оценка 0.00");
- });
- }
- }
- public class Student
- {
- public Student(string lastName, string initials, int clas, string itemName, int mark)
- {
- LastName = lastName;
- Initials = initials;
- Class = clas;
- ItemName = itemName;
- Mark = mark;
- }
- public string LastName;
- public string Initials;
- public int Class;
- public string ItemName;
- public int Mark;
- }
Advertisement
Add Comment
Please, Sign In to add comment