Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. public static void Main()
  8. {
  9. Dictionary<string, List<string>> concertInfo = new Dictionary<string, List<string>>();
  10. Dictionary<string, int> concertTime = new Dictionary<string, int>();
  11. int totalTime = 0;
  12.  
  13. while (true)
  14. {
  15. string input = Console.ReadLine();
  16.  
  17. if (input == "start of concert")
  18. {
  19. break;
  20. }
  21.  
  22. string[] tokens = input.Split("; ");
  23.  
  24. if (tokens[0] == "Add")
  25. {
  26.  
  27. string[] members = tokens[2].Split(", ");
  28.  
  29. if (concertInfo.ContainsKey(tokens[1]) == false)
  30. {
  31. concertInfo[tokens[1]] = new List<string>();
  32. }
  33.  
  34. for (int i = 0; i < members.Length; i++)
  35. {
  36. concertInfo[tokens[1]].Add(members[i]);
  37. }
  38. }
  39.  
  40. else if (tokens[0] == "Play")
  41. {
  42. string nameBand = tokens[1];
  43. int time = int.Parse(tokens[2]);
  44.  
  45. if (concertTime.ContainsKey(nameBand))
  46. {
  47. concertTime[nameBand] += time;
  48. totalTime += time;
  49. }
  50. else
  51. {
  52. concertTime[nameBand] = 0;
  53. concertTime[nameBand] += time;
  54. totalTime += time;
  55. }
  56.  
  57. }
  58. }
  59.  
  60.  
  61. string filter = Console.ReadLine();
  62.  
  63. Console.WriteLine($"Total time: {totalTime}");
  64.  
  65. foreach (var item in concertTime.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  66. {
  67. Console.WriteLine($"{item.Key} -> {item.Value}");
  68. }
  69.  
  70. foreach (var kvp in concertInfo.Where(x=>x.Key == filter))
  71. {
  72. Console.WriteLine($"{kvp.Key}");
  73.  
  74. foreach (var item in kvp.Value.Distinct())
  75. {
  76. Console.WriteLine($"=> {item}");
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement