Advertisement
simonradev

SoftUni Karaoke

Feb 8th, 2017
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SoftuniKaraoke
  8. {
  9.     public class SoftuniKaraoke
  10.     {
  11.         public static void Main()
  12.         {
  13.             string[] participants = Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
  14.             string[] avaliableSongs = Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
  15.  
  16.             Dictionary<string, List<string>> winners = new Dictionary<string, List<string>>();
  17.  
  18.             string inputLine = Console.ReadLine();
  19.             while (inputLine != "dawn")
  20.             {
  21.                 string[] singerInfo = inputLine.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
  22.  
  23.                 string singer = singerInfo[0];
  24.                 string song = singerInfo[1];
  25.                 string award = singerInfo[2];
  26.  
  27.                 if (!participants.Any(s => s == singer) || !avaliableSongs.Any(s => s == song))
  28.                 {
  29.                     inputLine = Console.ReadLine();
  30.  
  31.                     continue;
  32.                 }
  33.  
  34.                 if (!winners.ContainsKey(singer))
  35.                 {
  36.                     winners.Add(singer, new List<string>());
  37.                 }
  38.  
  39.                 winners[singer].Add(award);
  40.  
  41.                 inputLine = Console.ReadLine();
  42.             }
  43.  
  44.             if (winners.Count == 0)
  45.             {
  46.                 Console.WriteLine("No awards");
  47.  
  48.                 return;
  49.             }
  50.  
  51.             foreach (KeyValuePair<string, List<string>> pair in winners.OrderByDescending(a => a.Value.Count).ThenBy(n => n.Key))
  52.             {
  53.                 List<string> awards = pair.Value.Distinct().ToList();
  54.  
  55.                 Console.WriteLine($"{pair.Key}: {awards.Count} awards");
  56.                 foreach (string award in awards.OrderBy(n => n))
  57.                 {
  58.                     Console.WriteLine($"--{award}");
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement