Advertisement
Guest User

Сръбско Unleashed

a guest
Feb 19th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10.Сръбско_Unleashed
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string singer;
  12. string venue;
  13. int price = 0;
  14. int tickets = 0;
  15. int income = 0;
  16.  
  17. List<string> input = Console.ReadLine().Split(' ').ToList();
  18.  
  19. Dictionary<string, Dictionary<string, int>> concerts = new Dictionary<string, Dictionary<string, int>>();
  20. while (input[0] != "End")
  21. {
  22. if (!IsValid(input))
  23. {
  24. input = Console.ReadLine().Split(' ').ToList();
  25. continue;
  26. }
  27.  
  28. int currentMember = 0;
  29. List<string> thisSinger = new List<string>();
  30. while (!input[currentMember].StartsWith("@"))
  31. {
  32. thisSinger.Add(input[currentMember]);
  33. currentMember++;
  34. }
  35.  
  36. singer = string.Join(" ", thisSinger);
  37.  
  38. List<string> thisVenue = new List<string>();
  39. for (int i = currentMember; i < input.Count - 2; i++)
  40. {
  41. thisVenue.Add(input[i]);
  42. }
  43. venue = string.Join(" ", thisVenue);
  44. venue = venue.Remove(0, 1);
  45.  
  46. price = int.Parse(input[input.Count - 2]);
  47. tickets = int.Parse(input[input.Count - 1]);
  48. income = price * tickets;
  49.  
  50. if (!concerts.ContainsKey(venue))
  51. {
  52. Dictionary<string, int> currentSinger = new Dictionary<string, int>();
  53. currentSinger.Add(singer, income);
  54. concerts.Add(venue, currentSinger);
  55. }
  56. else
  57. {
  58. if (!concerts[venue].ContainsKey(singer))
  59. concerts[venue].Add(singer, income);
  60. else
  61. concerts[venue][singer] += income;
  62. }
  63. input = Console.ReadLine().Split(' ').ToList();
  64. }
  65.  
  66. foreach (var pair in concerts)
  67. {
  68. Console.WriteLine($"{pair.Key}");
  69. foreach (var performer in pair.Value.OrderByDescending(x => x.Value))
  70. {
  71. Console.WriteLine($"# {performer.Key} -> {performer.Value}");
  72. }
  73. }
  74.  
  75. }
  76. static bool IsValid(List<string> input)
  77. {
  78. bool hasAValidVenue = false;
  79. int indexOfVenueStart = 0;
  80. for (int i = 0; i < input.Count; i++)
  81. {
  82. if (input[i].StartsWith("@"))
  83. {
  84. hasAValidVenue = true;
  85. indexOfVenueStart = i;
  86. break;
  87. }
  88. }
  89.  
  90. if (hasAValidVenue == false) return false;
  91. if (indexOfVenueStart < 1 || indexOfVenueStart > 3) return false;
  92. if (indexOfVenueStart > input.Count - 3 || indexOfVenueStart < input.Count - 5) return false;
  93.  
  94. try
  95. {
  96. int.Parse(input[input.Count - 2]);
  97. int.Parse(input[input.Count - 1]);
  98. }
  99. catch
  100. {
  101. return false;
  102. }
  103.  
  104. return true;
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement