Advertisement
Guest User

srabsko_unleashed_2

a guest
Oct 12th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 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 splitted = line.Split('@');
  24.                 var name = splitted[0];
  25.  
  26.                 if (name[name.Length - 1] != ' ')
  27.                 {
  28.                     line = Console.ReadLine();
  29.                     continue;
  30.                 }
  31.  
  32.                 Stack<string> venuePrices = new Stack<string>(splitted[1].Split());
  33.                 if (venuePrices.Count < 3)
  34.                 {
  35.                     line = Console.ReadLine();
  36.                     continue;
  37.                 }
  38.  
  39.                 int ticketPrice = 0;
  40.                 int ticketCount = 0;
  41.                 try
  42.                 {
  43.                     ticketPrice = int.Parse(venuePrices.Pop().Trim());
  44.                     ticketCount = int.Parse(venuePrices.Pop().Trim());
  45.                 }
  46.                 catch (Exception e)
  47.                 {
  48.                     line = Console.ReadLine();
  49.                     continue;
  50.                 }
  51.  
  52.                 var venue = string.Join(" ", venuePrices.Reverse()).Trim();
  53.  
  54.                 if (!events.ContainsKey(venue))
  55.                 {
  56.                     events.Add(venue, new Dictionary<string, int>());
  57.                 }
  58.  
  59.                 if (!events[venue].ContainsKey(name))
  60.                 {
  61.                     events[venue].Add(name, 0);
  62.                 }
  63.  
  64.                 events[venue][name] += (ticketPrice * ticketCount);
  65.  
  66.                 line = Console.ReadLine();
  67.             }
  68.  
  69.  
  70.             foreach (var city in events)
  71.             {
  72.                 Console.WriteLine(city.Key.Trim());
  73.                 foreach (var performance in city.Value.OrderByDescending(t => t.Value))
  74.                 {
  75.                     Console.WriteLine("#  {0} -> {1}", performance.Key.Trim(), performance.Value);
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement