sivancheva

SrubskoUnleashed

Oct 22nd, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _21_10_SrubskoUnleashed
  9. {
  10. class SrubskoUnleashed
  11. {
  12. static void Main(string[] args)
  13. {
  14. var input = Console.ReadLine();
  15. var pattern = new Regex(@"^(?<singer>[A-Za-z\s]+)\s{1}@(?<venue>[A-Za-z\s]+)\s{1}(?<price>[\d]+)\s{1}(?<ticketCount>[\d]+)$");
  16.  
  17.  
  18. var result = new Dictionary<string, Dictionary<string, long>>();
  19. while (input!= "End")
  20. {
  21.  
  22. var match = pattern.Match(input);
  23.  
  24. if (!match.Success)
  25. {
  26. input = Console.ReadLine();
  27. continue;
  28. }
  29.  
  30. var singer = match.Groups["singer"].Value;
  31. var venue = match.Groups["venue"].Value;
  32. int price = int.Parse(match.Groups["price"].Value);
  33. long ticketCount = int.Parse(match.Groups["ticketCount"].Value);
  34. long profit = (long)price * ticketCount;
  35.  
  36. if (!result.ContainsKey(venue))
  37. {
  38. result.Add(venue, new Dictionary<string, long>());
  39. result[venue].Add(singer, profit);
  40. }
  41. else if(!result[venue].ContainsKey(singer))
  42. {
  43. result[venue][singer] = profit;
  44. }
  45. else
  46. {
  47. result[venue][singer] += profit;
  48. }
  49.  
  50. input = Console.ReadLine();
  51.  
  52. }
  53.  
  54. foreach (var item in result)
  55. {
  56. Console.WriteLine($"{item.Key}");
  57. foreach (var singer in item.Value.OrderByDescending(x => x.Value))
  58. {
  59. Console.WriteLine($"# {singer.Key} -> {singer.Value}");
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment