Advertisement
DyNaMiXx7

Untitled

Mar 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 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.             var courses = new Dictionary<string, List<string>>();
  12.  
  13.             string input = string.Empty;
  14.             while ((input = Console.ReadLine()) != "end")
  15.             {
  16.                 string[] tokens = input.Split(" : ");
  17.                 string courseName = tokens[0];
  18.                 string studetName = tokens[1];
  19.  
  20.                 if (!courses.ContainsKey(courseName))
  21.                 {
  22.                     courses.Add(courseName, new List<string>());
  23.                     courses[courseName].Add(studetName);
  24.                 }
  25.                 else
  26.                 {
  27.                     courses[courseName].Add(studetName);
  28.                 }
  29.             }
  30.  
  31.             foreach (var course in courses.OrderByDescending(x => x.Value.Count))
  32.             {
  33.                 Console.WriteLine($"{course.Key}: {course.Value.Count}");
  34.                 Console.WriteLine($"-- {string.Join(Environment.NewLine + "-- ", course.Value.OrderBy(x => x))}");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement