Advertisement
NastySwipy

Dictionaries_Lambda_Expressions_LINQ - 10. Сръбско Unleashed

Apr 27th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07b_Dictionaries_Lambda_Expressions_LINQ_Exercises
  6. {
  7.     class Dictionaries_Lambda_Expressions_LINQ_Exercises
  8.     {
  9.       static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, long>> lineUp = new Dictionary<string, Dictionary<string, long>>();
  12.            
  13.  
  14.             while (true)
  15.             {
  16.                 string[] input = Console.ReadLine().Split(new char[] { '@' }).ToArray();
  17.                 if (input[0].Equals("End"))
  18.                 {
  19.                     break;
  20.                 }
  21.                 string artistName = input[0].Trim();
  22.                 string[] concertTicketsAndMoney = input[1].Split();
  23.                 if (concertTicketsAndMoney.Length < 3 || !input[0].EndsWith(" "))
  24.                 {
  25.                     continue;
  26.                 }
  27.  
  28.                 int ticketsCount = 0;
  29.                 int ticketsPrice = 0;
  30.  
  31.                 try
  32.                 {
  33.                     ticketsCount = int.Parse(concertTicketsAndMoney[concertTicketsAndMoney.Length - 1]);
  34.                     ticketsPrice = int.Parse(concertTicketsAndMoney[concertTicketsAndMoney.Length - 2]);
  35.                 }
  36.  
  37.                 catch
  38.                 {
  39.  
  40.                     continue;
  41.                 }
  42.  
  43.                 string venue = "";
  44.                 for (int i = 0; i < concertTicketsAndMoney.Length - 2; i++)
  45.                 {
  46.                     venue += concertTicketsAndMoney[i] + " ";
  47.                 }
  48.                 venue = venue.TrimEnd();
  49.  
  50.                
  51.                 if (!lineUp.ContainsKey(venue))
  52.                 {
  53.                     lineUp.Add(venue, new Dictionary<string, long>());
  54.                 }
  55.                 if (!lineUp[venue].ContainsKey(artistName))
  56.                 {
  57.                     lineUp[venue].Add(artistName, 0);
  58.                 }
  59.                 lineUp[venue][artistName] += (long)ticketsPrice * ticketsCount;
  60.             }
  61.  
  62.             foreach (var venue in lineUp)
  63.             {
  64.                 Console.WriteLine(venue.Key);
  65.                 foreach (var singer in lineUp[venue.Key].OrderByDescending(x => x.Value))
  66.                 {
  67.                     Console.WriteLine($"#  {singer.Key} -> {singer.Value}");
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement