Advertisement
mastersan12

P06.Cources

Mar 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06.Cources
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var courses = new Dictionary<string,List<string>>();
  12.            
  13.             string cmd;
  14.             while ((cmd=Console.ReadLine()) != "end")
  15.             {
  16.                 List<string> info = cmd.Split(" : ").ToList();
  17.                 string courseName = info[0];
  18.                 string studentName = info[1];
  19.                
  20.  
  21.                 if (!courses.ContainsKey(courseName))
  22.                 {
  23.                     var students = new List<string>
  24.                     {
  25.                         studentName
  26.                     };
  27.                     courses.Add(courseName, students);
  28.                    
  29.                 }
  30.                 else
  31.                 {
  32.                     courses[courseName].Add(studentName);
  33.                 }
  34.                
  35.             }
  36.             foreach (var item in courses.OrderByDescending(x=>x.Value.Count))
  37.             {
  38.                 Console.WriteLine($"{item.Key}: {item.Value.Count}");
  39.                 var orderStudents = item.Value.OrderBy(x => x).ToList();
  40.                 foreach (var student in orderStudents)
  41.                 {
  42.                     Console.WriteLine($"-- {student}");
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement