Guest User

Untitled

a guest
May 22nd, 2018
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 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 ConsoleApp5
  8. {
  9. class MaxSequenceOfEqualElement
  10. {
  11. static void Main(string[] args)
  12.  
  13. {
  14. Dictionary<string, Dictionary<string, ulong>> performerInfo = new Dictionary<string, Dictionary<string, ulong>>();
  15. string performer = "";
  16. string venue = "";
  17. ulong ticketPrice = 0;
  18. ulong ticketCount = 0;
  19. ulong totalCurrentProfit = 0;
  20.  
  21. while (true)
  22. {
  23. string input = Console.ReadLine();
  24.  
  25. if (input.StartsWith("End"))
  26. {
  27. break;
  28. }
  29.  
  30. string[] checkInvalid = input.Split(' ',StringSplitOptions.RemoveEmptyEntries).ToArray();
  31.  
  32. bool startsWithAt = false;
  33.  
  34. foreach (var element in checkInvalid)
  35. {
  36. if (element.StartsWith("@"))
  37. {
  38. startsWithAt = true;
  39. }
  40. }
  41.  
  42. if (!startsWithAt)
  43. {
  44. continue;
  45. }
  46.  
  47. long digit;
  48.  
  49. bool isDigit = long.TryParse(checkInvalid[checkInvalid.Length - 1], out digit);
  50. bool isDigit1 = long.TryParse(checkInvalid[checkInvalid.Length - 2], out digit);
  51.  
  52. if (!isDigit || !isDigit1)
  53. {
  54. continue;
  55. }
  56.  
  57. if (checkInvalid.Length < 4)
  58. {
  59. continue;
  60. }
  61.  
  62. string[] arr = input.Split('@').ToArray();
  63.  
  64. performer = arr[0];
  65.  
  66. string[] venuePriceTickets = arr[1].Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
  67.  
  68.  
  69. ticketCount = ulong.Parse(venuePriceTickets[venuePriceTickets.Length - 1]);
  70. ticketPrice = ulong.Parse(venuePriceTickets[venuePriceTickets.Length - 2]);
  71. totalCurrentProfit = ticketPrice * ticketCount;
  72.  
  73. string[] venueArr = venuePriceTickets.SkipLast(2).ToArray();
  74.  
  75. venue = string.Join(" ", venueArr);
  76.  
  77. if (performerInfo.ContainsKey(venue))
  78. {
  79. if (performerInfo[venue].ContainsKey(performer))
  80. {
  81. performerInfo[venue][performer] += totalCurrentProfit;
  82. }
  83. else
  84. {
  85. performerInfo[venue].Add(performer, totalCurrentProfit);
  86. }
  87. }
  88. else
  89. {
  90. Dictionary<string, ulong> currentDict = new Dictionary<string, ulong>();
  91. currentDict.Add(performer, totalCurrentProfit);
  92. performerInfo.Add(venue, currentDict);
  93. }
  94.  
  95. }
  96.  
  97. foreach (var kvp in performerInfo)
  98. {
  99. Console.WriteLine(kvp.Key);
  100.  
  101. foreach (var name in kvp.Value.OrderByDescending(x=>x.Value))
  102. {
  103. Console.WriteLine($"# {name.Key}-> {name.Value}");
  104. }
  105. }
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment