Advertisement
Guest User

SoftuniKaraoke2

a guest
Oct 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. namespace _04_Sets_and_Dicts_Exer
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<string> namesOfSingers = Console.ReadLine()
  12.                .Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  13.                .ToList();
  14.  
  15.             List<string> songs = Console.ReadLine()
  16.                 .Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  17.                 .ToList();
  18.  
  19.             Dictionary<string, List<string>> allBullshits = new Dictionary<string, List<string>>();
  20.  
  21.             string songSinging = Console.ReadLine();
  22.  
  23.             while (songSinging != "dawn")
  24.             {
  25.                 string[] songList = songSinging.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
  26.  
  27.                 string nameOutput = songList[0];
  28.                 string song = songList[1];
  29.                 string award = songList[2];
  30.  
  31.                 if (namesOfSingers.Any(a => a == nameOutput) && songs.Any(a => a == song))
  32.                 {
  33.  
  34.                     if (!allBullshits.ContainsKey(nameOutput))
  35.                     {
  36.                         allBullshits.Add(nameOutput, new List<string>());
  37.                     }
  38.                     if (!allBullshits[nameOutput].Any(e => e == award))
  39.                     {
  40.                         allBullshits[nameOutput].Add(award);
  41.                     }
  42.                 }
  43.  
  44.                 songSinging = Console.ReadLine();
  45.             }
  46.  
  47.             if (!allBullshits.Any())
  48.             {
  49.                 Console.WriteLine("No awards");
  50.                 return;
  51.             }
  52.  
  53.             foreach (var singer in allBullshits.OrderByDescending(e => e.Value.Count).ThenBy(e => e.Key))
  54.             {
  55.                 Console.WriteLine($"{singer.Key}: {singer.Value.Count} awards");
  56.  
  57.                 foreach (var award in singer.Value.OrderBy(e => e))
  58.                 {
  59.                     Console.WriteLine($"--{award}");
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement