Advertisement
YavorGrancharov

SoftUni_Karaoke

Aug 19th, 2017
126
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.  
  5. namespace SoftUni_Karaoke
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> participants = Console.ReadLine()
  12.                 .Split(new string[] { ", " },
  13.                 StringSplitOptions.RemoveEmptyEntries).ToList();
  14.  
  15.             List<string> songs = Console.ReadLine()
  16.                 .Split(new string[] { ", " },
  17.                 StringSplitOptions.RemoveEmptyEntries).ToList();
  18.  
  19.             string input = Console.ReadLine();
  20.  
  21.             Dictionary<string, List<string>> awarded =
  22.                 new Dictionary<string, List<string>>();
  23.  
  24.             while (input != "dawn")
  25.             {
  26.                 string[] parts = input
  27.                     .Split(new string[] { ", " },
  28.                     StringSplitOptions.RemoveEmptyEntries);
  29.  
  30.                 string name = parts[0];
  31.                 string song = parts[1];
  32.                 string award = parts[2];
  33.                
  34.                 if (!participants.Any(p => p == name) || !songs.Any(s => s == song))
  35.                 {
  36.                     input = Console.ReadLine();
  37.                     continue;
  38.                 }
  39.  
  40.                 if (!awarded.ContainsKey(name))
  41.                 {
  42.                     awarded.Add(name, new List<string>());
  43.                 }
  44.                 awarded[name].Add(award);
  45.  
  46.                 input = Console.ReadLine();
  47.             }
  48.  
  49.             if (awarded.Count == 0)
  50.             {
  51.                 Console.WriteLine("No awards");
  52.             }
  53.  
  54.             foreach (var singer in awarded
  55.                 .OrderByDescending(x => x.Value.Distinct()
  56.                 .ToList().Count)
  57.                 .ThenBy(x => x.Key))
  58.             {
  59.                 List<string> awards = singer.Value.Distinct().ToList();
  60.  
  61.                 Console.WriteLine($"{singer.Key}: {awards.Count} awards");
  62.                 foreach (string award in awards.OrderBy(x => x))
  63.                 {
  64.                     Console.WriteLine($"--{award}");
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement