Advertisement
bacco

sarbianUnleashed

Jun 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace sarbianUnleashed
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.  
  12.         {
  13.             var dict = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             while (true)
  16.             {
  17.                 string input = Console.ReadLine();
  18.  
  19.                 if (input == "End")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.  
  25.  
  26.                 string correctInputPattern = @"(([a-zA-Z]+\s){1,3})@(([a-zA-Z]+\s){1,3})(\d+)\s(\d+)";
  27.  
  28.  
  29.  
  30.                 if (Regex.IsMatch(input, correctInputPattern))
  31.                 {
  32.                     Match match = Regex.Match(input, correctInputPattern);
  33.  
  34.                     var place = match.Groups[3].Value.Trim();
  35.  
  36.                     var singer = match.Groups[1].Value.Trim();
  37.  
  38.                     var ticketsPrice = int.Parse(match.Groups[5].Value);
  39.                     var ticketsCount = int.Parse(match.Groups[6].Value);
  40.  
  41.                     var totalMoney = ticketsCount * ticketsPrice;
  42.  
  43.  
  44.  
  45.                     if ( ! dict.ContainsKey(place))
  46.                     {
  47.                         dict[place] = new Dictionary<string, int>();
  48.                     }
  49.                     if ( ! dict[place].ContainsKey(singer))
  50.                     {
  51.                         dict[place][singer]= 0;
  52.                     }
  53.                     dict[place][singer] += totalMoney;
  54.  
  55.                 }
  56.             }
  57.  
  58.             foreach (var place in dict)
  59.             {
  60.                 Console.WriteLine($"{place.Key}");
  61.  
  62.                 foreach (var pair in place.Value.OrderByDescending( x => x.Value))
  63.                 {
  64.                     Console.WriteLine($"#  {pair.Key} -> {pair.Value}");
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement