Advertisement
Guest User

Problem 2. SoftUni Karaoke

a guest
Jun 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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 Exerciese
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var participansInKaraoke = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => x.Trim());
  14. var songsInKaraoke = Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => x.Trim());
  15.  
  16. var peopleAwards = new Dictionary<string, HashSet<string>>();
  17.  
  18. while (true)
  19. {
  20. var tokens = Console.ReadLine().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); ;
  21. if (tokens[0] == "dawn")
  22. {
  23. break;
  24. }
  25.  
  26. var participan = tokens[0].Trim();
  27. var song = tokens[1].Trim();
  28. var award = tokens[2];
  29.  
  30. if (participansInKaraoke.Contains(participan) && songsInKaraoke.Contains(song))
  31. {
  32. if (!peopleAwards.ContainsKey(participan))
  33. {
  34. peopleAwards[participan] = new HashSet<string>();
  35. }
  36. peopleAwards[participan].Add(award);
  37. }
  38. else
  39. {
  40. continue;
  41. }
  42.  
  43. }
  44. if (peopleAwards.Keys.Count == 0)
  45. {
  46. Console.WriteLine("No awards");
  47. }
  48. else
  49. {
  50. foreach (var item in peopleAwards.Where(x => x.Value.Count > 0).OrderByDescending(x => x.Key).ThenBy(x => x.Key).ThenBy(x => x.Value))
  51. {
  52. Console.WriteLine($"{item.Key}: {item.Value.Count} awards");
  53. foreach (var i in item.Value)
  54. {
  55. Console.WriteLine($"--{i.Trim()}");
  56. }
  57. }
  58. }
  59.  
  60.  
  61. }
  62.  
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement