Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Problem04
- {
- static void Main()
- {
- var srubskoInfo = new Dictionary<string, Dictionary<string, long>>();
- Regex validation = new Regex(@"((([a-zA-Z])+\s))+@(([a-zA-Z])+\s{0,1}([a-zA-Z]))*(\s[0-9]+)+");
- Regex foundVenue = new Regex(@"@([a-zA-z]+\s)+");
- Regex foundPerformer = new Regex(@"^([a-zA-z]+)(\s*[a-zA-z])*");
- Regex foundTicketsData = new Regex(@"\d+\s\d+");
- string input = Console.ReadLine();
- while (input != "End")
- {
- if (validation.IsMatch(input))
- {
- var performerName = foundPerformer.Match(input).Value.Trim();
- var moneyData = foundTicketsData.Match(input).Value.Split();
- var performingPlaceAsArr = foundVenue.Match(input).Value.Split(new [] { '@', ' '}, StringSplitOptions.RemoveEmptyEntries);
- var performingPlace = string.Join(" ", performingPlaceAsArr);
- long money = long.Parse(moneyData[0]) * long.Parse(moneyData[1]);
- if (!srubskoInfo.ContainsKey(performingPlace))
- {
- srubskoInfo[performingPlace] = new Dictionary<string, long>();
- }
- if (!srubskoInfo[performingPlace].ContainsKey(performerName))
- {
- srubskoInfo[performingPlace].Add(performerName,money);
- }
- else
- {
- srubskoInfo[performingPlace][performerName] += money;
- }
- }
- else
- {
- input = Console.ReadLine();
- continue;
- }
- input = Console.ReadLine();
- }
- foreach (var city in srubskoInfo)
- {
- Console.WriteLine(city.Key);
- foreach (var pair in city.Value.OrderByDescending(pair => pair.Value))
- {
- Console.WriteLine("# {0} -> {1}", pair.Key, pair.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment