Advertisement
EmoRz

SoftUni_Karaoke

Jun 16th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SoftUniKaraoke
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] participants = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  12.             string[] songs = Console.ReadLine().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  13.             string[] clearSongs = new string[songs.Length];
  14.             for (int s = 0; s < songs.Length; s++)
  15.             {
  16.                 string temp = songs[s].Trim();
  17.                 clearSongs[s] = temp;
  18.             }
  19.             string performance = Console.ReadLine();
  20.             Dictionary<string, Dictionary<string, int>> data = new Dictionary<string, Dictionary<string, int>>();
  21.             // name of songer and awards
  22.             bool isGetAwards = true;
  23.             while (performance !="dawn")
  24.             {
  25.                 string name = performance.Split(new char[] { ','})[0];
  26.                 string songPerforming = performance.Split(new char[] { ',' })[1].Trim();
  27.                 string awardTheyGet = performance.Split(new char[] { ',' })[2].Trim();
  28.                 //
  29.                 if (participants.Contains(name) && clearSongs.Contains(songPerforming))
  30.                 {
  31.                     isGetAwards = false;
  32.                     if (!data.ContainsKey(name))
  33.                     {
  34.                         Dictionary<string, int> current = new Dictionary<string, int>();
  35.                         current.Add(awardTheyGet, 0);
  36.                         data.Add(name, current);
  37.                     }
  38.                     if (!data[name].ContainsKey(awardTheyGet))
  39.                     {
  40.                         data[name].Add(awardTheyGet, 0);
  41.                     }
  42.                 }
  43.                 performance = Console.ReadLine();
  44.             }
  45.             foreach (var singer in data.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  46.             {
  47.                 Console.Write(singer.Key+": ");
  48.                 Console.WriteLine(singer.Value.Count+" awards");
  49.                 foreach (var item in singer.Value.OrderBy(x => x.Key))
  50.                 {
  51.                     Console.WriteLine("--" + item.Key);
  52.  
  53.                 }
  54.             }
  55.             if (isGetAwards)
  56.             {
  57.                 Console.WriteLine("No awards");
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement