Advertisement
YavorGrancharov

Problem_2.SoftUni_Karaoke

Nov 1st, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_2.SoftUni_Karaoke
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> participants = Console.ReadLine()
  12.                 .Split(new string[] { ", ", }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .ToList();
  14.             List<string> songs = Console.ReadLine(
  15.                 ).Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  16.                 .ToList();
  17.  
  18.             Dictionary<string, HashSet<string>> data = new Dictionary<string, HashSet<string>>();
  19.  
  20.             string input = Console.ReadLine();
  21.             while (input != "dawn")
  22.             {
  23.                 string[] tokens = input
  24.                     .Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  25.                     .ToArray();
  26.                 string name = tokens[0];
  27.                 string song = tokens[1];
  28.                 string award = tokens[2];
  29.  
  30.                 if (participants.Contains(name) && songs.Contains(song))
  31.                 {
  32.                     if (!data.ContainsKey(name))
  33.                     {
  34.                         data.Add(name, new HashSet<string>());
  35.                     }
  36.                     data[name].Add(award);
  37.                 }
  38.                 input = Console.ReadLine();
  39.             }
  40.             if (data.Count() == 0)
  41.             {
  42.                 Console.WriteLine("No awards");
  43.             }
  44.             else
  45.             {
  46.                 foreach (var entry in data
  47.                     .Where(x => x.Value.Count() > 0)
  48.                     .OrderByDescending(x => x.Value.Count())
  49.                     .ThenBy(x => x.Key))
  50.                 {
  51.                     Console.WriteLine("{0}: {1} awards", entry.Key, entry.Value.Distinct().Count());
  52.                     HashSet<string> awards = entry.Value;
  53.                     foreach (var award in awards.OrderBy(x => x))
  54.                     {
  55.                         Console.WriteLine("--{0}", award);
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement