Advertisement
Lamms

SrabskoUnleashed

Oct 16th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 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. using System.Text.RegularExpressions;
  7.  
  8. namespace _04PopulationCounter
  9. {
  10.     class Program
  11.     {
  12.         static void Main()
  13.         {
  14.             string input = Console.ReadLine();
  15.             string pattern = @"(.*?)\s@(.*?)\s(\d+)\s(\d+)";
  16.             Regex regex = new Regex(pattern);
  17.            
  18.             Dictionary<string, Dictionary<string,long>> performances = new Dictionary<string, Dictionary<string, long>>();
  19.             while (input != "End")
  20.             {
  21.                 try
  22.                 {
  23.                     Match match = regex.Match(input);
  24.                     long profit = 0L;
  25.                     //string[] inputLine = input.Split(' ').ToArray();
  26.                     string singer = match.Groups[1].Value;
  27.                     //Console.WriteLine(singer);
  28.                     string venue = match.Groups[2].Value.Trim();
  29.                     long price = long.Parse(match.Groups[3].Value.Trim());
  30.                     //  Console.WriteLine(price);
  31.                     long people = long.Parse(match.Groups[4].Value.Trim());
  32.                     // Console.WriteLine(people);
  33.                      profit = (price) * (people);
  34.                     //   Console.WriteLine(profit);
  35.                     if (!performances.ContainsKey(venue))
  36.                     {                        
  37.                         performances[venue] = new Dictionary<string, long>();
  38.                         //performances[venue] = singer.OrderBy(x => x.Value);
  39.                     }
  40.                     if (!performances[venue].ContainsKey(singer))
  41.                     {
  42.                         performances[venue].Add(singer, profit);
  43.                     }
  44.                     else if (performances[venue].ContainsKey(singer))
  45.                     {
  46.  
  47.                         performances[venue][singer] += profit;
  48.                     }
  49.                     input = Console.ReadLine();
  50.                 }
  51.                 catch(Exception e)
  52.                 {
  53.                     input = Console.ReadLine();
  54.                 }
  55.             }
  56.  
  57.             var sortedPopulationData = performances
  58.              .OrderByDescending(x => x.Value
  59.                     .Sum(y => y.Value));
  60.  
  61.             foreach (var count in performances)
  62.             {  
  63.                Console.WriteLine(count.Key);
  64.                var orderedCityData = count.Value
  65.                   .OrderByDescending(x => x.Value);
  66.                foreach (var item in orderedCityData)
  67.                {
  68.                    Console.Write("#  {0} -> ", item.Key);
  69.                    Console.WriteLine(item.Value);
  70.                }          
  71.             }            
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement