Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SrubskoUnleashed
  6. {
  7. class Program
  8. {
  9. private static Dictionary<string, Dictionary<string, long>> data = new Dictionary<string, Dictionary<string, long>>();
  10.  
  11. private static void CollectData (List<string> command)
  12. {
  13. int ticketPrice, ticketCount, venueIndex;
  14. string venue, singer;
  15. if(int.TryParse(command.Last(), out ticketCount)
  16. && int.TryParse(command[command.Count - 2], out ticketPrice))
  17. {
  18. venueIndex = command.FindIndex(x => x.StartsWith("@"));
  19. if (venueIndex < 0)
  20. {
  21. return;
  22. }
  23. ticketCount = int.Parse(command.Last());
  24. command.RemoveAt(command.Count - 1);
  25. ticketPrice = int.Parse(command.Last());
  26. command.RemoveAt(command.Count - 1);
  27.  
  28. var temp = command
  29. .GetRange(venueIndex, command.Count - venueIndex)
  30. .ToArray();
  31. var temp2 = command
  32. .GetRange(0, command.Count - temp.Length)
  33. .ToArray();
  34. venue = string.Join(" ", temp);
  35. venue = venue.Remove(0, 1);
  36. singer = string.Join(" ", temp2);
  37.  
  38. if (!data.ContainsKey(venue))
  39. {
  40. data[venue] = new Dictionary<string, long>();
  41. }
  42. if (!data[venue].ContainsKey(singer))
  43. {
  44. data[venue].Add(singer, 0);
  45. }
  46. data[venue][singer] += (long)ticketCount * ticketPrice;
  47. }
  48. }
  49.  
  50. private static void PrintResult()
  51. {
  52. foreach (var venue in data)
  53. {
  54. Console.WriteLine($"{venue.Key}");
  55. foreach (var singer in venue.Value.OrderByDescending(x => x.Value))
  56. {
  57. Console.WriteLine($"# {singer.Key} -> {singer.Value}");
  58. }
  59. }
  60. }
  61.  
  62. static void Main(string[] args)
  63. {
  64. var input = Console.ReadLine();
  65.  
  66. var command = new List<string>();
  67. while(input.ToLower() != "end")
  68. {
  69. command = input
  70. .Split(' ')
  71. .ToList();
  72. if(command.Count >= 4)
  73. {
  74. CollectData(command);
  75. }
  76.  
  77.  
  78. input = Console.ReadLine();
  79. }
  80. PrintResult();
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement