Advertisement
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;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _04PopulationCounter
- {
- class Program
- {
- static void Main()
- {
- string input = Console.ReadLine();
- string pattern = @"(.*?)\s@(.*?)\s(\d+)\s(\d+)";
- Regex regex = new Regex(pattern);
- Dictionary<string, Dictionary<string,long>> performances = new Dictionary<string, Dictionary<string, long>>();
- while (input != "End")
- {
- try
- {
- Match match = regex.Match(input);
- long profit = 0L;
- //string[] inputLine = input.Split(' ').ToArray();
- string singer = match.Groups[1].Value;
- //Console.WriteLine(singer);
- string venue = match.Groups[2].Value.Trim();
- long price = long.Parse(match.Groups[3].Value.Trim());
- // Console.WriteLine(price);
- long people = long.Parse(match.Groups[4].Value.Trim());
- // Console.WriteLine(people);
- profit = (price) * (people);
- // Console.WriteLine(profit);
- if (!performances.ContainsKey(venue))
- {
- performances[venue] = new Dictionary<string, long>();
- //performances[venue] = singer.OrderBy(x => x.Value);
- }
- if (!performances[venue].ContainsKey(singer))
- {
- performances[venue].Add(singer, profit);
- }
- else if (performances[venue].ContainsKey(singer))
- {
- performances[venue][singer] += profit;
- }
- input = Console.ReadLine();
- }
- catch(Exception e)
- {
- input = Console.ReadLine();
- }
- }
- var sortedPopulationData = performances
- .OrderByDescending(x => x.Value
- .Sum(y => y.Value));
- foreach (var count in performances)
- {
- Console.WriteLine(count.Key);
- var orderedCityData = count.Value
- .OrderByDescending(x => x.Value);
- foreach (var item in orderedCityData)
- {
- Console.Write("# {0} -> ", item.Key);
- Console.WriteLine(item.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement