Advertisement
Guest User

Untitled

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