deleriumbg

Srubsko Unleashed

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