Advertisement
silvana1303

courses

Jul 20th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace mid_exam
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var command = Console.ReadLine().Split(" : ").ToArray();
  12.  
  13.             var courses = new Dictionary<string, List<string>>();
  14.  
  15.             while (command[0] != "end")
  16.             {
  17.                 if (!courses.ContainsKey(command[0]))
  18.                 {
  19.                     courses.Add(command[0], new List<string>());
  20.                 }
  21.                
  22.                 courses[command[0]].Add(command[1]);
  23.          
  24.                 command = Console.ReadLine().Split(" : ").ToArray();
  25.             }
  26.  
  27.             foreach (var course in courses.OrderByDescending(x => x.Value.Count))
  28.             {
  29.                 Console.WriteLine("{0}: {1}", course.Key, course.Value.Count);
  30.        
  31.                 foreach (var name in course.Value.OrderBy(n => n))
  32.                 {
  33.                     Console.WriteLine("-- {0}", name);
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement