Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. namespace _10.SrybskoUnleashed_Regex_Az
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class SrybskoUnleashedRegex
  9.     {
  10.         public static void Main()
  11.         {
  12.             var venues = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             string pattern = @"(?<name>([a-zA-Z]+\s?){1,3}) @(?<venue>([A-Za-z]+\s?){1,3}) (?<price>\d+) (?<count>\d+)";
  15.             var regex = new Regex(pattern);
  16.  
  17.             string line = Console.ReadLine();
  18.  
  19.             while (line != "End")
  20.             {
  21.                 if (!regex.IsMatch(line))
  22.                 {
  23.                     line = Console.ReadLine();
  24.                     continue;
  25.                 }
  26.                 else
  27.                 {
  28.                     Match match = regex.Match(line);
  29.  
  30.                     string artist = match.Groups["name"].Value;
  31.                     string venueName = match.Groups["venue"].Value;
  32.                     int ticketPrice = int.Parse(match.Groups["price"].Value);
  33.                     int ticketCount = int.Parse(match.Groups["count"].Value);
  34.  
  35.                     if (!venues.ContainsKey(venueName))
  36.                     {
  37.                         venues[venueName] = new Dictionary<string, int>();
  38.                     }
  39.  
  40.                     if (!venues[venueName].ContainsKey(artist))
  41.                     {
  42.                         venues[venueName][artist] = 0;
  43.                     }
  44.  
  45.                     venues[venueName][artist] += ticketPrice * ticketCount;
  46.  
  47.                     line = Console.ReadLine();
  48.                 }
  49.             }
  50.  
  51.             foreach (var outerKvp in venues)
  52.             {
  53.                 Console.WriteLine(outerKvp.Key);
  54.  
  55.                 var artistsAtVenue = outerKvp.Value;
  56.  
  57.                 foreach (var innerKvp in artistsAtVenue.OrderByDescending(x => x.Value))
  58.                 {
  59.                     Console.WriteLine($"#  {innerKvp.Key} -> {innerKvp.Value}");
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement