Advertisement
Guest User

Untitled

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