Advertisement
Guest User

SrabskoUnleashed

a guest
Feb 20th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. namespace _10.SrabskoUnleashed
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using System.Threading.Tasks;
  8.  
  9.     public class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.  
  14.             //singer @venue ticketsPrice ticketsCount
  15.             var dict = new Dictionary<string, Dictionary<string, long>>();
  16.  
  17.             var line = Console.ReadLine();
  18.  
  19.             while (line != "End")
  20.             {
  21.  
  22.                 if (!line.Contains(" @")) //in case invalid entry appears -> Dragana@Belgrade23 3500
  23.                 {
  24.                     line = Console.ReadLine();
  25.  
  26.                     continue;
  27.  
  28.                 }
  29.                 var allData = line.Split("@".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).ToArray();
  30.  
  31.                 var singerName = allData[0].Trim();
  32.                 var concertInfo = allData[1].Trim().Split(' ').ToArray();
  33.  
  34.                 if (concertInfo.Length < 3) //!!!!--- with it it uses too much memory, without it - gives 7th test wrong!
  35.                 {
  36.                     continue;
  37.                 }
  38.  
  39.                 var ticketCount = long.Parse(concertInfo[concertInfo.Length - 1]);
  40.                 var ticketPrice = long.Parse(concertInfo[concertInfo.Length - 2]);
  41.  
  42.                 var venue = string.Empty; //to add Space in the venue Name if the Name is more than 1 word
  43.                 for (int i = 0; i < concertInfo.Length - 2; i++)
  44.                 {
  45.                     venue += concertInfo[i] + " ";
  46.                 }
  47.                 venue.TrimEnd(); //to remove the Space added after the venue
  48.  
  49.                 //Venue check
  50.  
  51.                 if (!dict.ContainsKey(venue))
  52.                 {
  53.                     dict.Add(venue, new Dictionary<string, long>());
  54.                 }
  55.  
  56.                 //Singer in Venue check
  57.  
  58.                 if (!dict[venue].ContainsKey(singerName))
  59.                 {
  60.                     dict[venue].Add(singerName, 0);
  61.                 }
  62.                 //add Money value for each
  63.                 dict[venue][singerName] += (long)ticketPrice * ticketCount;
  64.                
  65.                 line = Console.ReadLine();
  66.             }
  67.  
  68.             foreach (var venuePair in dict)
  69.             {
  70.                 Console.WriteLine($"{venuePair.Key}");
  71.  
  72.                 foreach (var singerPair in dict[venuePair.Key].OrderByDescending(x => x.Value)) //as per  the Money value
  73.                 {
  74.                     Console.WriteLine($"#  {singerPair.Key} -> {singerPair.Value}"); //mind your spaces
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement