Advertisement
viraco4a

Srbsko

Feb 26th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 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 Srabsko
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. var AllData = new Dictionary<string, Dictionary<string, long>>(50);
  14. string inputLine = Console.ReadLine();
  15. while (inputLine != "End")
  16. {
  17. string[] splitTheSinger = inputLine
  18. .Split(new string[] { " @" }, StringSplitOptions.RemoveEmptyEntries)
  19. .ToArray();
  20. if (splitTheSinger.Length > 1)
  21. {
  22. string[] splitTheRest = splitTheSinger[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  23. if (splitTheRest.Length > 2)
  24. {
  25. long profit = 0;
  26. try
  27. {
  28. int ticketPrice = int.Parse(splitTheRest[splitTheRest.Length - 2]);
  29. int ticketsSold = int.Parse(splitTheRest[splitTheRest.Length - 1]);
  30. profit = ticketPrice * ticketsSold;
  31. }
  32. catch (Exception)
  33. {
  34. continue;
  35. }
  36. string[] splittedVenue = splitTheRest
  37. .Take(splitTheRest.Length - 2)
  38. .ToArray();
  39. string venue = string.Join(" ", splittedVenue);
  40. if (!AllData.ContainsKey(venue))
  41. {
  42. AllData[venue] = new Dictionary<string, long>(50);
  43. }
  44.  
  45. if (!AllData[venue].ContainsKey(splitTheSinger[0]))
  46. {
  47. AllData[venue][splitTheSinger[0]] = 0;
  48. }
  49.  
  50. AllData[venue][splitTheSinger[0]] += profit;
  51. }
  52. }
  53.  
  54. inputLine = Console.ReadLine();
  55. }
  56.  
  57. var finalData = OrderTheData(AllData);
  58.  
  59. foreach (var venue in finalData)
  60. {
  61. Console.WriteLine(venue.Key);
  62. foreach (var singer in venue.Value)
  63. {
  64. Console.WriteLine($"# {singer.Key} -> {singer.Value}");
  65. }
  66. }
  67. }
  68.  
  69. private static Dictionary<string, Dictionary<string, long>> OrderTheData(Dictionary<string, Dictionary<string, long>> AllData)
  70. {
  71. var finalData = new Dictionary<string, Dictionary<string, long>>();
  72. for (int i = 0; i < AllData.Count; i++)
  73. {
  74. var kvp = AllData
  75. .ElementAt(i)
  76. .Value.OrderByDescending(s => s.Value)
  77. .ToDictionary(x => x.Key, y => y.Value);
  78. finalData[AllData.ElementAt(i).Key] = new Dictionary<string, long>();
  79. finalData[AllData.ElementAt(i).Key] = kvp;
  80. }
  81.  
  82. return finalData;
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement