Advertisement
Dokka

10.SrabskoUnleashed

Oct 19th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 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.  
  7. namespace _10_SrabskoUnleashed
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             var folkersData = new Dictionary<string, Dictionary<string, long>>();
  16.  
  17.             GetFolkersData(folkersData, input);
  18.  
  19.             foreach (var venue in folkersData)
  20.             {
  21.                 Console.WriteLine($"{venue.Key}");
  22.  
  23.                 foreach (var singer in venue.Value.OrderByDescending(x => x.Value))
  24.                 {
  25.                     Console.WriteLine("#  {0} -> {1}", singer.Key, singer.Value);
  26.                 }
  27.             }
  28.         }
  29.  
  30.         private static void GetFolkersData(Dictionary<string, Dictionary<string, long>> folkersData, string input)
  31.         {
  32.             while (input != "End")
  33.             {
  34.                 if (input.Contains('@'))
  35.                 {
  36.                     string[] singerName = input.Split('@');
  37.  
  38.                     if (singerName[1].Split().Length >= 3)
  39.                     {
  40.                         string singer = singerName[0].Substring(0, singerName[0].Length - 1);
  41.                         List<string> checkerSingerName = singer.Split().ToList();
  42.  
  43.                         if (checkerSingerName.Count <= 3)
  44.                         {
  45.                             List<string> venueAndTickets = singerName[1].Split().ToList();
  46.  
  47.                             if (venueAndTickets.Count >= 3)
  48.                             {
  49.                                 if (long.TryParse(venueAndTickets[venueAndTickets.Count - 1], out _)
  50.                                     && long.TryParse(venueAndTickets[venueAndTickets.Count - 2], out _))
  51.                                 {
  52.                                     long ticketCount = long.Parse(venueAndTickets[venueAndTickets.Count - 1]);
  53.                                     venueAndTickets.RemoveAt(venueAndTickets.Count - 1);
  54.  
  55.                                     long ticketPrice = long.Parse(venueAndTickets[venueAndTickets.Count - 1]);
  56.                                     venueAndTickets.RemoveAt(venueAndTickets.Count - 1);
  57.  
  58.                                     long ticketMoney = ticketCount * ticketPrice;
  59.                                     string venue = string.Join(" ", venueAndTickets);
  60.  
  61.                                     List<string> checkerVenueName = venue.Split().ToList();
  62.  
  63.                                     if (checkerVenueName.Count <= 3)
  64.                                     {
  65.                                         if (!folkersData.ContainsKey(venue))
  66.                                         {
  67.                                             folkersData[venue] = new Dictionary<string, long>();
  68.                                         }
  69.                                         if (!folkersData[venue].ContainsKey(singer))
  70.                                         {
  71.                                             folkersData[venue][singer] = ticketMoney;
  72.                                         }
  73.                                         else
  74.                                         {
  75.                                             folkersData[venue][singer] += ticketMoney;
  76.                                         }
  77.                                     }
  78.                                 }
  79.                             }
  80.                         }
  81.                     }
  82.                 }
  83.                 input = Console.ReadLine();
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement