Advertisement
Niicksana

SoftUni Karaoke

Aug 25th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._SoftUni_Karaoke
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. // Programming Fundamentals Retake Exam - 6 January 2017
  12.  
  13. List<string> names = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  14. List<string> songs = Console.ReadLine().Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
  15. string command = Console.ReadLine();
  16.  
  17. Dictionary<string, Dictionary<string, int>> awards = new Dictionary<string, Dictionary<string, int>>();
  18.  
  19. while (command != "dawn")
  20. {
  21. string[] tokens = command.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  22. string name = tokens[0];
  23. string song = tokens[1];
  24. string award = tokens[2];
  25.  
  26. if (names.Contains(name))
  27. {
  28. if (songs.Contains(song))
  29. {
  30. if (!awards.ContainsKey(name))
  31. {
  32. awards.Add(name, new Dictionary<string, int>());
  33. awards[name].Add(award, 0);
  34. }
  35.  
  36. if (!awards[name].ContainsKey(award))
  37. {
  38. awards[name].Add(award, 0);
  39. }
  40.  
  41. if(awards[name].ContainsKey(award))
  42. {
  43. awards[name][award]++;
  44. }
  45. }
  46. }
  47.  
  48. command = Console.ReadLine();
  49. }
  50.  
  51. if (awards.Count == 0)
  52. {
  53. Console.WriteLine("No awards");
  54. return;
  55. }
  56.  
  57. foreach (var name in awards.OrderByDescending(x => x.Value.Keys.Count()).ThenBy(x => x.Key))
  58. {
  59. Console.WriteLine($"{name.Key}: {name.Value.Count()} awards");
  60. foreach (var award in name.Value.OrderBy(x => x.Key))
  61. {
  62. Console.WriteLine($"--{award.Key}");
  63. }
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement