Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string,List<string>> coursesAndStudents = new Dictionary<string,List<string>>();
- while(true)
- {
- string command = Console.ReadLine();
- if (command == "end")
- {
- break;
- }
- string[] tokens = command.Split(':').Select(s => s.Trim()).ToArray();
- string courseName = tokens[0];
- string studentName = tokens[1];
- if (!coursesAndStudents.ContainsKey(courseName))
- {
- coursesAndStudents.Add(courseName, new List<string>());
- coursesAndStudents[courseName].Add(studentName);
- }
- else
- {
- coursesAndStudents[courseName].Add(studentName);
- }
- }
- foreach (var kvp in coursesAndStudents.OrderByDescending(x=>x.Value.Count))
- {
- Console.WriteLine("{0}: {1}",kvp.Key,kvp.Value.Count());
- foreach (var name in kvp.Value.OrderBy(n=>n))
- {
- Console.WriteLine("-- {0}",name);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement