Advertisement
radidim

P06.Courses (C# Shell App Paste)

Jul 29th, 2020 (edited)
2,123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.            var courses = new Dictionary<string, List<string>>();
  15.            var registeredStudents = 0;
  16.            while (true)
  17.            {
  18.             var input = Console.ReadLine();
  19.             if(input == "end")
  20.             {
  21.                 break;
  22.             }
  23.             var items = input.Split(":");
  24.             var courseName = items[0];
  25.             var studentName = items[1];
  26.            
  27.             if(!courses.ContainsKey(courseName))
  28.             {
  29.                 courses[courseName] = new List<string>();
  30.             }
  31.             courses[courseName].Add(studentName);
  32.            
  33.            
  34.            }
  35.            foreach(var kvp in courses.OrderByDescending(x=>x.Value.Count).ThenBy(x=>x.Key))
  36.            {
  37.             Console.WriteLine($"{kvp.Key} : {string.Join(string.Empty, kvp.Value.Count)}");
  38.             Console.WriteLine($"-- {string.Join(string.Empty, kvp.Value)}");
  39.            }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement