Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _10.SrabskoUnleashed
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- public class Program
- {
- public static void Main()
- {
- //singer @venue ticketsPrice ticketsCount
- var dict = new Dictionary<string, Dictionary<string, long>>();
- var line = Console.ReadLine();
- while (line != "End")
- {
- if (!line.Contains(" @")) //in case invalid entry appears -> Dragana@Belgrade23 3500
- {
- line = Console.ReadLine();
- continue;
- }
- var allData = line.Split("@".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).ToArray();
- var singerName = allData[0].Trim();
- var concertInfo = allData[1].Trim().Split(' ').ToArray();
- if (concertInfo.Length < 3) //!!!!--- with it it uses too much memory, without it - gives 7th test wrong!
- {
- continue;
- }
- var ticketCount = long.Parse(concertInfo[concertInfo.Length - 1]);
- var ticketPrice = long.Parse(concertInfo[concertInfo.Length - 2]);
- var venue = string.Empty; //to add Space in the venue Name if the Name is more than 1 word
- for (int i = 0; i < concertInfo.Length - 2; i++)
- {
- venue += concertInfo[i] + " ";
- }
- venue.TrimEnd(); //to remove the Space added after the venue
- //Venue check
- if (!dict.ContainsKey(venue))
- {
- dict.Add(venue, new Dictionary<string, long>());
- }
- //Singer in Venue check
- if (!dict[venue].ContainsKey(singerName))
- {
- dict[venue].Add(singerName, 0);
- }
- //add Money value for each
- dict[venue][singerName] += (long)ticketPrice * ticketCount;
- line = Console.ReadLine();
- }
- foreach (var venuePair in dict)
- {
- Console.WriteLine($"{venuePair.Key}");
- foreach (var singerPair in dict[venuePair.Key].OrderByDescending(x => x.Value)) //as per the Money value
- {
- Console.WriteLine($"# {singerPair.Key} -> {singerPair.Value}"); //mind your spaces
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement