daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06._Courses
  6. {
  7.     class StartUp
  8.     {
  9.         static void Main()
  10.         {
  11.             var coursesStudents = new Dictionary<string, List<string>>();
  12.  
  13.             while (true)
  14.             {
  15.                 string line = Console.ReadLine();
  16.                 if (line == "end")
  17.                 {
  18.                     break;
  19.                 }
  20.  
  21.                 string[] splitedLine = line.Split(" : ");
  22.                 string course = splitedLine[0];
  23.                 string name = splitedLine[1];
  24.  
  25.                 if (!coursesStudents.ContainsKey(course))
  26.                 {
  27.                     List<string> students = new List<string>();
  28.                     students.Add(name);
  29.                     coursesStudents.Add(course, students);
  30.                 }
  31.                 else
  32.                 {
  33.                     coursesStudents[course].Add(name);
  34.                 }              
  35.             }
  36.  
  37.             var dict = coursesStudents.OrderByDescending(x => x.Value.Count);
  38.  
  39.             foreach (var kvp in dict)
  40.             {
  41.                 Console.WriteLine($"{kvp.Key}: {kvp.Value.Count}");
  42.  
  43.                 var orderStudents = kvp.Value.OrderBy(x => x).ToList();
  44.                 foreach (var student in orderStudents)
  45.                 {
  46.                     Console.WriteLine($"-- {student}");
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top