Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 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 _02.SoftUni_Karaoke
  8. {
  9. public class Program
  10. {
  11. public static void Main()
  12. {
  13.  
  14. var participants = Console.ReadLine().Split(new[] { ',', ' ' }
  15. , StringSplitOptions.RemoveEmptyEntries)
  16. .ToList();
  17.  
  18. var songs = Console.ReadLine().Split(new[] { ',' }
  19. , StringSplitOptions.RemoveEmptyEntries).Select(y => y.Trim())
  20. .ToList();
  21. var result = new Dictionary<string, List<string>>();
  22.  
  23. if (participants.Count >= 1 && participants.Count <= 100 && songs.Count >= 1 && songs.Count <= 100)
  24. {
  25.  
  26. var stagePerformance = Console.ReadLine();
  27. if (stagePerformance == "dawn")
  28. {
  29. Console.WriteLine("No awards");
  30. return;
  31. }
  32. while (stagePerformance != "dawn")
  33. {
  34.  
  35. var token = stagePerformance.Split(new[] { ',' }
  36. , StringSplitOptions.RemoveEmptyEntries)
  37. .ToList();
  38. var participant = token[0].Trim();
  39. var songForParticipant = token[1].Trim();
  40. var award = token[2].Trim();
  41. if (participants.Contains(participant) && songs.Contains(songForParticipant)) //possible bug
  42. {
  43. if (!result.ContainsKey(participant))
  44. {
  45. result.Add(participant, new List<string>());
  46. }
  47. if (!result[participant].Contains(award))
  48. {
  49. result[participant].Add(award);
  50. }
  51. }
  52.  
  53. stagePerformance = Console.ReadLine();
  54. }
  55. }
  56. else
  57. {
  58. Console.WriteLine("No awards");
  59. return;
  60. }
  61. foreach (var KvP in result
  62. .OrderByDescending(x => x.Value.Count).ThenBy(y => y.Key))
  63. {
  64. if (KvP.Value.Contains(string.Empty))
  65. {
  66. Console.WriteLine("No awards");
  67. break;
  68. }
  69. Console.WriteLine($"{KvP.Key}: {result[KvP.Key].Count} awards");
  70. foreach (var award in KvP.Value.OrderBy(x => x))
  71. {
  72. Console.WriteLine($"--{award}");
  73. }
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement