Advertisement
simonradev

FixedSoftUniKaraoke

Feb 8th, 2017
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 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
  52.                                                                 .OrderByDescending(a => a.Value.Distinct().ToList().Count)
  53.                                                                 .ThenBy(n => n.Key))
  54.             {
  55.                 List<string> awards = pair.Value.Distinct().ToList();
  56.  
  57.                 Console.WriteLine($"{pair.Key}: {awards.Count} awards");
  58.                 foreach (string award in awards.OrderBy(n => n))
  59.                 {
  60.                     Console.WriteLine($"--{award}");
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement