WindFell

SoftUni Karaoke

Jun 14th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class SoftUniKaraoke
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         string[] participants = Console.ReadLine()
  10.             .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  11.             .Select(x => x.Trim())
  12.             .ToArray();
  13.         string[] songs = Console.ReadLine()
  14.             .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  15.             .Select(x => x.Trim())
  16.             .ToArray();
  17.         string input;
  18.  
  19.         var awards = new Dictionary<string, List<string>>();
  20.  
  21.         while ((input = Console.ReadLine()) != "dawn")
  22.         {
  23.             string[] performance = input
  24.             .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  25.             .Select(x => x.Trim())
  26.             .ToArray();
  27.  
  28.             string participant = performance[0];
  29.             string song = performance[1];
  30.             string award = performance[2];
  31.  
  32.             if (participants.Contains(participant) == false || songs.Contains(song) == false)
  33.             {
  34.                 continue;
  35.             }
  36.  
  37.             if (awards.ContainsKey(participant) == false)
  38.             {
  39.                 awards.Add(participant, new List<string>());
  40.             }
  41.  
  42.             if (awards[participant].Contains(award) == false)
  43.             {
  44.                 awards[participant].Add(award);
  45.             }
  46.         }
  47.  
  48.         if (awards.Count < 1)
  49.         {
  50.             Console.WriteLine("No awards");
  51.             Environment.Exit(0);
  52.         }
  53.  
  54.         foreach (var pair in awards.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  55.         {
  56.             Console.WriteLine($"{pair.Key}: {pair.Value.Count} awards");
  57.  
  58.             foreach (var award in pair.Value.OrderBy(x => x))
  59.             {
  60.                 Console.WriteLine($"--{award}");
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment