Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 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 P10.Сръбско_Unleashed
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. const string pattern = @"(.*?) @(.*?) (\d+) (\d+)";
  15.  
  16. var report = new Dictionary<string, Dictionary<string, long>>();
  17.  
  18. string data = Console.ReadLine();
  19.  
  20. while (data != "End")
  21. {
  22. if (!Regex.IsMatch(data, pattern))
  23. {
  24. data = Console.ReadLine();
  25. continue;
  26. }
  27.  
  28. var match = Regex.Match(data, pattern);
  29. string singer = match.Groups[1].Value;
  30. string venue = match.Groups[2].Value;
  31. int ticketPrice = int.Parse(match.Groups[3].Value);
  32. int ticketCount = int.Parse(match.Groups[4].Value);
  33.  
  34. long totalMoney = (long)ticketCount * ticketPrice;
  35.  
  36. if (!report.ContainsKey(venue))
  37. {
  38. report.Add(venue, new Dictionary<string, long>());
  39. }
  40.  
  41. if (!report[venue].ContainsKey(singer))
  42. {
  43. report[venue].Add(singer, 0);
  44. }
  45.  
  46. report[venue][singer] += totalMoney;
  47.  
  48. data = Console.ReadLine();
  49. }
  50.  
  51. foreach (var venue in report)
  52. {
  53. Console.WriteLine($"{venue.Key}");
  54.  
  55. var earningsSorted = report[venue.Key].OrderByDescending(x => x.Value);
  56.  
  57. foreach (var singer in earningsSorted)
  58. {
  59. Console.WriteLine($"# {singer.Key} -> {singer.Value}");
  60. }
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement