Advertisement
Guest User

Untitled

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