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;
- namespace Srabsko
- {
- class Program
- {
- static void Main()
- {
- var AllData = new Dictionary<string, Dictionary<string, long>>(50);
- string inputLine = Console.ReadLine();
- while (inputLine != "End")
- {
- string[] splitTheSinger = inputLine
- .Split(new string[] { " @" }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (splitTheSinger.Length > 1)
- {
- string[] splitTheRest = splitTheSinger[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- if (splitTheRest.Length > 2)
- {
- long profit = 0;
- try
- {
- int ticketPrice = int.Parse(splitTheRest[splitTheRest.Length - 2]);
- int ticketsSold = int.Parse(splitTheRest[splitTheRest.Length - 1]);
- profit = ticketPrice * ticketsSold;
- }
- catch (Exception)
- {
- continue;
- }
- string[] splittedVenue = splitTheRest
- .Take(splitTheRest.Length - 2)
- .ToArray();
- string venue = string.Join(" ", splittedVenue);
- if (!AllData.ContainsKey(venue))
- {
- AllData[venue] = new Dictionary<string, long>(50);
- }
- if (!AllData[venue].ContainsKey(splitTheSinger[0]))
- {
- AllData[venue][splitTheSinger[0]] = 0;
- }
- AllData[venue][splitTheSinger[0]] += profit;
- }
- }
- inputLine = Console.ReadLine();
- }
- var finalData = OrderTheData(AllData);
- foreach (var venue in finalData)
- {
- Console.WriteLine(venue.Key);
- foreach (var singer in venue.Value)
- {
- Console.WriteLine($"# {singer.Key} -> {singer.Value}");
- }
- }
- }
- private static Dictionary<string, Dictionary<string, long>> OrderTheData(Dictionary<string, Dictionary<string, long>> AllData)
- {
- var finalData = new Dictionary<string, Dictionary<string, long>>();
- for (int i = 0; i < AllData.Count; i++)
- {
- var kvp = AllData
- .ElementAt(i)
- .Value.OrderByDescending(s => s.Value)
- .ToDictionary(x => x.Key, y => y.Value);
- finalData[AllData.ElementAt(i).Key] = new Dictionary<string, long>();
- finalData[AllData.ElementAt(i).Key] = kvp;
- }
- return finalData;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement