Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- Dictionary<string, Dictionary<string, int>> venuesSingersEarnings = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "End")
- {
- break;
- }
- if (input.Contains(" @") == false)
- {
- continue;
- }
- string singerName = input.Substring(0, input.IndexOf(" @"));
- string[] splitInput = input.Substring(input.IndexOf("@") + 1).Split();
- if (splitInput.Length < 3 || splitInput.Length > 4)
- {
- continue;
- }
- string place = splitInput[0];
- if (splitInput.Length == 4)
- {
- place += " " + splitInput[1];
- splitInput = splitInput.Skip(2).ToArray();
- }
- else
- {
- splitInput = splitInput.Skip(1).ToArray();
- }
- int ticketPrice = 0;
- int ticketCount = 0;
- if (!int.TryParse(splitInput[0], out ticketPrice))
- {
- continue;
- }
- if (!int.TryParse(splitInput[1], out ticketCount))
- {
- continue;
- }
- int totalEarning = ticketCount * ticketPrice;
- if (!venuesSingersEarnings.ContainsKey(place))
- {
- venuesSingersEarnings[place] = new Dictionary<string, int>();
- }
- if (venuesSingersEarnings[place].ContainsKey(singerName))
- {
- venuesSingersEarnings[place][singerName] += totalEarning;
- }
- else
- {
- venuesSingersEarnings[place][singerName] = totalEarning;
- }
- }
- foreach (KeyValuePair<string, Dictionary<string, int>> venueSingerEarning in venuesSingersEarnings)
- {
- Console.WriteLine($"{venueSingerEarning.Key}");
- foreach (KeyValuePair<string, int> singerEarning in venueSingerEarning.Value.OrderBy(kvp => -kvp.Value))
- {
- Console.WriteLine($"# {singerEarning.Key} -> {singerEarning.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement