Advertisement
Guest User

Srubsko

a guest
Oct 12th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. class SrubskoUnleashed
  7. {
  8.     static void Main()
  9.     {
  10.         Dictionary<string, Dictionary<string, long>> database = new Dictionary<string, Dictionary<string, long>>();
  11.         while (true)
  12.         {
  13.             string line = Console.ReadLine();
  14.  
  15.             if (line == "End")
  16.             {
  17.                 break;
  18.             }
  19.  
  20.             string pattern = @"(([a-zA-Z\s*]+)\s+(@[a-zA-Z\s*]+)\s+(\d+)\s+(\d+))";
  21.             MatchCollection matches = Regex.Matches(line, pattern);
  22.  
  23.             foreach (Match match in matches)
  24.             {
  25.                 if (match.Groups[1].Success)
  26.                 {
  27.                     string singer = match.Groups[2].Value;
  28.                     string venue = match.Groups[3].Value.Remove(0, 1);
  29.                     long ticketPrice = long.Parse(match.Groups[4].Value);
  30.                     long ticketsCount = long.Parse(match.Groups[5].Value);
  31.  
  32.                     if (!database.ContainsKey(venue))
  33.                     {
  34.                         database.Add(venue, new Dictionary<string, long>());
  35.                     }
  36.                     if (!database[venue].ContainsKey(singer))
  37.                     {
  38.                         database[venue].Add(singer, 0L);
  39.                     }
  40.  
  41.                     database[venue][singer] += ticketsCount * ticketPrice;
  42.                 }
  43.             }
  44.         }
  45.  
  46.         foreach (KeyValuePair<string, Dictionary<string, long>> pair in database)
  47.         {
  48.             Console.WriteLine("{0}", pair.Key);
  49.  
  50.             var sortedDict = from entry in pair.Value orderby entry.Value descending select entry;
  51.             foreach (var entry in sortedDict)
  52.             {
  53.                 Console.WriteLine("#  {0} -> {1}", entry.Key, entry.Value);
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement