Advertisement
Guest User

SrubskoUnleashed

a guest
Feb 17th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 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.  
  7. namespace _10Problem_SrubskoUnleashed
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string venues;
  14. string singerName;
  15. int ticketPrice;
  16. long ticketCount;
  17. long totalMoney;
  18.  
  19. var placeAndSingers = new Dictionary<string, Dictionary<string, long>>();
  20. const string pattern = @"([a-zA-Z]+\s){1,3}@([a-zA-Z0-9]+\s){1,3}[0-9]+\s[0-9]+";
  21.  
  22. string concertInfo = Console.ReadLine();
  23.  
  24. while (concertInfo.Equals("End") == false)
  25. {
  26. var isTheInputValid = Regex.Match(concertInfo, pattern);
  27.  
  28. if (isTheInputValid.Success)
  29. {
  30. string[] splitConcertInfo = concertInfo.Split('@');
  31. string[] rightPart = splitConcertInfo[1].Trim().Split();
  32.  
  33. singerName = splitConcertInfo[0].Trim();
  34. venues = string.Join(" ", rightPart.Take(rightPart.Length-2).ToArray());
  35.  
  36.  
  37. ticketPrice = int.Parse(rightPart[rightPart.Length - 2]);
  38. ticketCount = long.Parse(rightPart[rightPart.Length - 1]);
  39. totalMoney = ticketPrice * ticketCount;
  40.  
  41. if (placeAndSingers.ContainsKey(venues) == false)
  42. {
  43. placeAndSingers.Add(venues, new Dictionary<string, long>());
  44. placeAndSingers[venues].Add(singerName, totalMoney);
  45. }
  46. else
  47. {
  48. if (placeAndSingers[venues].ContainsKey(singerName) == false)
  49. {
  50. placeAndSingers[venues].Add(singerName, totalMoney);
  51. }
  52. else
  53. {
  54. placeAndSingers[venues][singerName] += totalMoney;
  55. }
  56. }
  57. }
  58.  
  59. concertInfo = Console.ReadLine();
  60. }
  61.  
  62. foreach (var place in placeAndSingers)
  63. {
  64. Console.WriteLine($"{place.Key}");
  65.  
  66. foreach (var singerAndMoney in place.Value.OrderByDescending(x => x.Value))
  67. {
  68. Console.WriteLine($"# {singerAndMoney.Key} -> {singerAndMoney.Value}");
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement