Advertisement
Pazzobg

ProgrammingFundamentals-Lambda&LINQ-SrabskoUnleashed_2

Jun 6th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.97 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.                 bool foundAt = false;
  18.                 for (int i = 0; i < input.Length; i++)
  19.                 {
  20.                     if (input[i].Contains("@"))
  21.                     {
  22.                         foundAt = true;
  23.                         break;
  24.                     }
  25.                 }
  26.  
  27.                 if (!foundAt)
  28.                 {
  29.                     input = Console.ReadLine().Split(' ');
  30.                     continue;
  31.                 }
  32.  
  33.                 long outValue = 0;
  34.                 bool lastIsNumber = long.TryParse(input[input.Length - 1], out outValue);
  35.                 bool forelastIsNumber = long.TryParse(input[input.Length - 2], out outValue);
  36.                 if (!lastIsNumber || !forelastIsNumber)
  37.                 {
  38.                     input = Console.ReadLine().Split(' ');
  39.                     continue;
  40.                 }
  41.  
  42.                 if (input.Length >= 4) // Strah loze pazi :D
  43.                 {
  44.                     string artist = GetArtist(input);
  45.                     string venue = GetVenue(input);
  46.                     string ticketsSold = input[input.Length - 1];
  47.                     string ticketPrice = input[input.Length - 2];
  48.                     long totalTicketRevenue = long.Parse(ticketPrice) * long.Parse(ticketsSold);
  49.  
  50.                     if (!venuesDict.ContainsKey(venue))
  51.                     {
  52.                         venuesDict[venue] = new Dictionary<string, long>();
  53.                     }
  54.  
  55.                     if (!venuesDict[venue].ContainsKey(artist))
  56.                     {
  57.                         venuesDict[venue][artist] = 0;
  58.                     }
  59.  
  60.                     venuesDict[venue][artist] += totalTicketRevenue;
  61.  
  62.                     input = Console.ReadLine().Split(' ');
  63.                 }
  64.                 else
  65.                 {
  66.                     input = Console.ReadLine().Split(' ');
  67.                 }
  68.             }
  69.  
  70.             foreach (var kvp in venuesDict)
  71.             {
  72.                 string venue = kvp.Key;
  73.                 var artistsAndProfit = kvp.Value;
  74.  
  75.                 Console.WriteLine(venue);
  76.  
  77.                 foreach (var kvpInner in artistsAndProfit.OrderByDescending(x => x.Value))
  78.                 {
  79.                     string artist = kvpInner.Key;
  80.                     long profit = kvpInner.Value;
  81.  
  82.                     Console.WriteLine($"#  {artist} -> {profit}");
  83.                 }
  84.             }
  85.         }
  86.  
  87.         public static string GetArtist(string[] input)
  88.         {
  89.             string name = string.Empty;
  90.  
  91.             for (int i = 0; i < input.Length; i++)
  92.             {
  93.                 if (!input[i].Contains("@"))
  94.                 {
  95.                     name += input[i];
  96.                     name += " ";
  97.                 }
  98.                 else
  99.                 {
  100.                     break;
  101.                 }
  102.             }
  103.  
  104.             return name.TrimEnd();
  105.         }
  106.  
  107.         public static string GetVenue(string[] input)
  108.         {
  109.             string venueName = string.Empty;
  110.             bool venueStarted = false;
  111.  
  112.             for (int i = 0; i < input.Length - 2; i++)
  113.             {
  114.                 if (input[i].Contains("@") && !venueStarted)
  115.                 {
  116.                     venueName += input[i];
  117.                     venueName += " ";
  118.                     venueStarted = true;
  119.                 }
  120.                 else if (venueStarted)
  121.                 {
  122.                     venueName += input[i];
  123.                     venueName += " ";
  124.                 }
  125.             }
  126.  
  127.             return venueName.Trim(new[] { '@', ' ' });
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement