Advertisement
Aborigenius

SoftUni Karaoke

Aug 28th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var result = new Dictionary<string, List<string>>();
  14.             List<string> participants = Console.ReadLine().Split(new string[] { ", " },
  15.                     StringSplitOptions.RemoveEmptyEntries).ToList();
  16.             List<string> songs = Console.ReadLine().Split(new string[] { ", " },
  17.                     StringSplitOptions.RemoveEmptyEntries).ToList();
  18.             string play = Console.ReadLine();
  19.  
  20.             while (play != "dawn")
  21.             {
  22.                 string[] input = play.Split(new string[] { ", " },
  23.                     StringSplitOptions.RemoveEmptyEntries);
  24.                 string participantName = input[0];
  25.                 string song = input[1];
  26.                 string award = input[2];
  27.  
  28.                 if (participants.Any(p => p.Contains(participantName))
  29.                     && songs.Any(s => s.Contains(song)))
  30.                 {
  31.                     if (!result.ContainsKey(participantName))
  32.                     {
  33.                         result.Add(participantName, new List<string>());
  34.                     }
  35.                     if (!result[participantName].Contains(award))
  36.                     {
  37.                         result[participantName].Add(award);
  38.                     }
  39.  
  40.                 }
  41.                 play = Console.ReadLine();
  42.             }
  43.             if (result.Count == 0)
  44.             {
  45.                 Console.WriteLine("No awards");
  46.             }
  47.             else
  48.             {
  49.                 foreach (var item in result.OrderByDescending(a => a.Value.Count)
  50.                     .ThenBy(name => name.Key.Length))
  51.                 {
  52.                     Console.WriteLine($"{item.Key}: {item.Value.Count} awards");
  53.                     foreach (var award in item.Value.OrderBy(award => award))
  54.                     {
  55.                         Console.WriteLine($"--{award}");
  56.                     }
  57.  
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement