Advertisement
Pazzobg

ProgrammingFundamentals-Lambda&LINQ-SrabskoUnleashed

Jun 6th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. namespace _10.SrybskoUnleashed
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class SrybskoUnleashed
  8.     {
  9.         public static void Main()
  10.         {
  11.             var venuesDict = new Dictionary<string, Dictionary<string, long>>();
  12.  
  13.             string[] input = Console.ReadLine().Split(' ');
  14.  
  15.             while (input[0] != "End")
  16.             {
  17.                 if (input.Length >= 4)
  18.                 {
  19.                     string artist = GetArtist(input);
  20.                     string venue = GetVenue(input);
  21.                     string ticketsSold = input[input.Length - 1];
  22.                     string ticketPrice = input[input.Length - 2];
  23.                     long totalTicketRevenue = long.Parse(ticketPrice) * long.Parse(ticketsSold);
  24.  
  25.                     if (!venuesDict.ContainsKey(venue))
  26.                     {
  27.                         venuesDict[venue] = new Dictionary<string, long>();
  28.                     }
  29.                     if (!venuesDict[venue].ContainsKey(artist))
  30.                     {
  31.                         venuesDict[venue][artist] = 0;
  32.                     }
  33.  
  34.                     venuesDict[venue][artist] += totalTicketRevenue;
  35.  
  36.  
  37.  
  38.                     input = Console.ReadLine().Split(' ');
  39.                 }
  40.                 else
  41.                 {
  42.                     input = Console.ReadLine().Split(' ');
  43.                 }
  44.             }
  45.  
  46.             foreach (var kvp in venuesDict)
  47.             {
  48.                 string venue = kvp.Key;
  49.                 var artistsAndProfit = kvp.Value;
  50.  
  51.                 Console.WriteLine(venue);
  52.  
  53.                 foreach (var kvpInner in artistsAndProfit.OrderByDescending(x => x.Value))
  54.                 {
  55.                     string artist = kvpInner.Key;
  56.                     long profit = kvpInner.Value;
  57.  
  58.                     Console.WriteLine($"#  {artist} -> {profit}");
  59.                 }
  60.             }
  61.         }
  62.  
  63.         public static string GetArtist(string[] input)
  64.         {
  65.             string name = string.Empty;
  66.  
  67.             for (int i = 0; i < input.Length; i++)
  68.             {
  69.                 if (!input[i].Contains("@"))
  70.                 {
  71.                     name += input[i];
  72.                     name += " ";
  73.                 }
  74.                 else
  75.                 {
  76.                     break;
  77.                 }
  78.             }
  79.  
  80.             return name.TrimEnd();
  81.         }
  82.  
  83.         public static string GetVenue(string[] input)
  84.         {
  85.             string venueName = string.Empty;
  86.             bool venueStarted = false;
  87.  
  88.             for (int i = 0; i < input.Length - 2; i++)
  89.             {
  90.                 if (input[i].Contains("@") && !venueStarted)
  91.                 {
  92.                     venueName += input[i];
  93.                     venueName += " ";
  94.                     venueStarted = true;
  95.                 }
  96.                 else if (venueStarted)
  97.                 {
  98.                     venueName += input[i];
  99.                     venueName += " ";
  100.                 }
  101.             }
  102.  
  103.             return venueName.Trim(new[] { '@', ' ' });
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement