Advertisement
miroLLL

10Problem-SrubskoUnleashed

Feb 16th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _10Problem_SrubskoUnleashed
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string venues;
  14.             string singerName;
  15.             int ticketPrice;
  16.             long ticketCount;
  17.             long totalMoney;
  18.  
  19.             var placeAndSingers = new Dictionary<string, Dictionary<string, long>>();
  20.             const string pattern = @"([a-zA-Z]+\s){1,3}@([a-zA-Z0-9]+\s){1,3}[0-9]+\s[0-9]+";
  21.  
  22.             string concertInfo = Console.ReadLine();
  23.  
  24.             while (concertInfo.Equals("End") == false)
  25.             {              
  26.                 var isTheInputValid = Regex.Match(concertInfo, pattern);
  27.  
  28.                 if (isTheInputValid.Success)
  29.                 {
  30.                     string[] splitConcertInfo = concertInfo.Split('@');
  31.                     string[] rightPart = splitConcertInfo[1].Trim().Split();
  32.  
  33.                     singerName = splitConcertInfo[0].Trim();
  34.                     venues = (rightPart[0]);
  35.  
  36.                     if (rightPart.Length == 4)
  37.                     {
  38.                         venues += " " + rightPart[1];
  39.                     }
  40.  
  41.                     ticketPrice = int.Parse(rightPart[rightPart.Length - 2]);
  42.                     ticketCount = long.Parse(rightPart[rightPart.Length - 1]);
  43.                     totalMoney = ticketPrice * ticketCount;
  44.  
  45.                     if (placeAndSingers.ContainsKey(venues) == false)
  46.                     {
  47.                         placeAndSingers.Add(venues, new Dictionary<string, long>());
  48.                         placeAndSingers[venues].Add(singerName, totalMoney);
  49.                     }
  50.                     else
  51.                     {
  52.                         if (placeAndSingers[venues].ContainsKey(singerName) == false)
  53.                         {
  54.                             placeAndSingers[venues].Add(singerName, totalMoney);
  55.                         }
  56.                         else
  57.                         {
  58.                             placeAndSingers[venues][singerName] += totalMoney;
  59.                         }
  60.                     }
  61.                 }
  62.  
  63.                 concertInfo = Console.ReadLine();
  64.             }
  65.  
  66.             foreach (var place in placeAndSingers)
  67.             {
  68.                 Console.WriteLine($"{place.Key}");
  69.  
  70.                 foreach (var singerAndMoney in place.Value.OrderByDescending(x => x.Value))
  71.                 {
  72.                     Console.WriteLine($"#  {singerAndMoney.Key} -> {singerAndMoney.Value}");
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement