Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _06._Courses
- {
- class Courses
- {
- static void Main()
- {
- Dictionary<string, List<string>> dictCourses = new Dictionary<string, List<string>>();
- string command = Console.ReadLine();
- while (command != "end")
- {
- string[] currentCommand = command.Split(" : ").ToArray();
- string courseName = currentCommand[0];
- string studnetName = currentCommand[1];
- if (!dictCourses.ContainsKey(courseName))
- {
- dictCourses[courseName] = new List<string>();
- dictCourses[courseName].Add(studnetName);
- }
- else
- {
- dictCourses[courseName].Add(studnetName);
- }
- command = Console.ReadLine();
- }
- dictCourses = dictCourses
- .OrderByDescending(x => x.Value.Count())
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var student in dictCourses)
- {
- Console.WriteLine($"{student.Key}: {student.Value.Count()}");
- student.Value.Sort();
- for (int i = 0; i < 1; i++)
- {
- Console.WriteLine($"-- {string.Join("\n-- ", student.Value)}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment