Advertisement
Guest User

srabsko_unleashed_1

a guest
Oct 12th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SrabskoUnlesashed
  8. {
  9.     using System.Text.RegularExpressions;
  10.  
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Regex regex = new Regex(@"[\D]+[ ][@](.*?)*[ ][\d]+[ ][\d]+");
  16.  
  17.             var line = Console.ReadLine();
  18.  
  19.             var events = new Dictionary<string, Dictionary<string, int>>();
  20.  
  21.             while (line != "End")
  22.             {
  23.                 var isMatch = regex.IsMatch(line);
  24.                 if (isMatch)
  25.                 {
  26.                     var splitted = line.Split('@');
  27.                     var venuePrices = splitted[1].Split();
  28.  
  29.                     var name = splitted[0].Trim();
  30.                     var venue = "";
  31.                     for (int i = 0; i < venuePrices.Length - 2; i++)
  32.                     {
  33.                         venue += venuePrices[i] + " ";
  34.                     }
  35.                     venue = venue.Trim();
  36.                     var price = int.Parse(venuePrices[venuePrices.Length - 1].Trim());
  37.                     var count = int.Parse(venuePrices[venuePrices.Length - 2].Trim());
  38.  
  39.                     if (!events.ContainsKey(venue))
  40.                     {
  41.                         events.Add(venue, new Dictionary<string, int>());
  42.                     }
  43.  
  44.                     if (!events[venue].ContainsKey(name))
  45.                     {
  46.                         events[venue].Add(name, 0);
  47.                     }
  48.  
  49.                     events[venue][name] += (price*count);
  50.                 }
  51.  
  52.                 line = Console.ReadLine();
  53.             }
  54.  
  55.             foreach (var city in events)
  56.             {
  57.                 Console.WriteLine(city.Key);
  58.                 foreach (var performance in city.Value.OrderByDescending(t => t.Value))
  59.                 {
  60.                     Console.WriteLine("#  {0} -> {1}", performance.Key, performance.Value);
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement