Advertisement
Guest User

6.Courses

a guest
Nov 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace _6.Courses
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.  
  11.             Dictionary<string, List<string>> students = new Dictionary<string, List<string>>();
  12.  
  13.             while (true)
  14.             {
  15.                 var input = Console.ReadLine().Split(" : ").ToArray();
  16.                 if (input[0] == "end")
  17.                 {
  18.                     break;
  19.                 }
  20.                 if (!students.ContainsKey(input[0]))
  21.                 {
  22.                     students.Add(input[0], new List<string>());
  23.                     students[input[0]].Add(input[1]);
  24.                 }
  25.                 else
  26.                 {
  27.                     students[input[0]].Add(input[1]);
  28.                 }
  29.             }
  30.  
  31.             students = students
  32.                 .OrderByDescending(x => x.Value.Count)
  33.                 .ThenBy(x => x.Value)
  34.                 .ToDictionary(x => x.Key, x => x.Value);
  35.  
  36.  
  37.  
  38.             foreach (var kvp in students)
  39.             {
  40.  
  41.                 Console.WriteLine($"{kvp.Key}: {kvp.Value.Count}");
  42.                 var list = kvp.Value;
  43.  
  44.                 foreach (var kvp2 in list)
  45.                 {
  46.                     Console.WriteLine($"-- {kvp2}");
  47.                 }
  48.  
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement