Advertisement
Guest User

SrubskoUnleashed

a guest
Oct 10th, 2016
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 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. using System.Threading.Tasks;
  7.  
  8. namespace _10.Сръбско_Unleashed
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var VenuesIncome = new Dictionary<string, Dictionary<string, long>>();
  15.  
  16.             string pattern = @"(\w+(?: \w+)*) @(\w+(?: \w+)*) (\d+) (\d+)";
  17.             Regex regex = new Regex(pattern);
  18.  
  19.             while (true)
  20.             {
  21.                 var inputedInfo = Console.ReadLine();
  22.                 if (inputedInfo == "End")
  23.                 {
  24.                     break;
  25.                 }
  26.                 if (!regex.IsMatch(inputedInfo))
  27.                 {
  28.                     continue;
  29.                 }
  30.                
  31.  
  32.                 var WholeInfoParts = inputedInfo.Split(new char[] { '@' }).ToArray();
  33.  
  34.                 //proverka dali sa tochno dumite
  35.                 if ((WholeInfoParts[0].Count(Char.IsWhiteSpace) == 0 ||
  36.                     WholeInfoParts[0].Count(Char.IsWhiteSpace) > 3) ||
  37.                     (WholeInfoParts[1].Count(Char.IsWhiteSpace) < 2 ||
  38.                     WholeInfoParts[1].Count(Char.IsWhiteSpace) > 4))
  39.                 {
  40.                     continue;
  41.                 }
  42.  
  43.                 string[] secondPartInfo = WholeInfoParts[1].Split().ToArray();
  44.  
  45.                 string venue = "";
  46.                 int ticketPrice = 0;
  47.                 int ticketsCount = 0;
  48.                 string singer = WholeInfoParts[0].Trim();
  49.  
  50.                 if (secondPartInfo.Length == 3)
  51.                 {
  52.                     venue = secondPartInfo[0];
  53.                     ticketPrice = int.Parse(secondPartInfo[1]);
  54.                     ticketsCount = int.Parse(secondPartInfo[2]);
  55.                 }
  56.                 else if (secondPartInfo.Length == 4)
  57.                 {
  58.                     venue = secondPartInfo[0] + " " + secondPartInfo[1];
  59.                     ticketPrice = int.Parse(secondPartInfo[2]);
  60.                     ticketsCount = int.Parse(secondPartInfo[3]);
  61.                 }
  62.                 else if (secondPartInfo.Length == 5)
  63.                 {
  64.                     venue = secondPartInfo[0] + " " + secondPartInfo[1] + " " + secondPartInfo[2];
  65.                     ticketPrice = int.Parse(secondPartInfo[3]);
  66.                     ticketsCount = int.Parse(secondPartInfo[4]);
  67.                 }
  68.  
  69.  
  70.                 if (!VenuesIncome.ContainsKey(venue))
  71.                 {
  72.                     VenuesIncome.Add(venue, new Dictionary<string, long>());
  73.                 }
  74.  
  75.                 if (!VenuesIncome[venue].ContainsKey(singer))
  76.                 {
  77.                     VenuesIncome[venue].Add(singer, 0);
  78.                 }
  79.  
  80.                 VenuesIncome[venue][singer] += ticketPrice * ticketsCount;
  81.  
  82.             }
  83.  
  84.             //print the venues
  85.  
  86.             foreach (var VenueData in VenuesIncome)
  87.             {
  88.                 Console.WriteLine(VenueData.Key);
  89.                 var orderedSingersList = VenueData.Value.OrderByDescending(x => x.Value).ToList();
  90.  
  91.                 foreach (var singerData in orderedSingersList)
  92.                 {
  93.                     Console.WriteLine($"#  {singerData.Key} -> {singerData.Value}");
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement