Advertisement
JordanB

Сръбско Unleashed

Jun 10th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace ConsoleApp14
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             var cities = new Dictionary<string, Dictionary<string, int>>();
  16.  
  17.             while (true)
  18.             {
  19.                 string input = Console.ReadLine();
  20.                 if (input=="End")
  21.                 {
  22.                     break;
  23.                 }
  24.                 string[] inputToArray = input.Split('@').ToArray();
  25.                 if (inputToArray.Length == 2)
  26.                 {
  27.                     //artist name
  28.                     string[] artistToArray = inputToArray[0].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToArray();
  29.                     string artist = string.Empty;
  30.                     if (artistToArray.Length <= 3)
  31.                     {
  32.                         artist = string.Join(" ", artistToArray);
  33.                     }
  34.                     else
  35.                     {
  36.                         continue;
  37.                     }
  38.                    
  39.                     //sumPrice
  40.                     List<string> cityAndPrice = inputToArray[1].Split().ToList();
  41.                     if (cityAndPrice.Count<3)
  42.                     {
  43.                         continue;
  44.                     }
  45.                     int ticketsCount = int.Parse(cityAndPrice[cityAndPrice.Count - 1]);
  46.                     cityAndPrice.RemoveAt(cityAndPrice.Count-1);
  47.                     int ticketsPrice = int.Parse(cityAndPrice[cityAndPrice.Count - 1]);
  48.                     cityAndPrice.RemoveAt(cityAndPrice.Count - 1);
  49.                     int sum = ticketsCount * ticketsPrice;
  50.  
  51.                     //city name
  52.                     string city = string.Empty;
  53.                     if (cityAndPrice.Count<=3)
  54.                     {
  55.                         city = string.Join(" ", cityAndPrice);
  56.                     }
  57.                     else
  58.                     {
  59.                         continue;
  60.                     }
  61.  
  62.                     //add in the dictionary
  63.                     if (!cities.ContainsKey(city))
  64.                     {
  65.                         cities.Add(city, new Dictionary<string, int>());
  66.                     }
  67.                     if (!cities[city].ContainsKey(artist))
  68.                     {
  69.                         cities[city].Add(artist, 0);
  70.                     }
  71.                     cities[city][artist] += sum;
  72.                 }
  73.             }
  74.  
  75.             foreach (var key in cities.Keys)
  76.             {
  77.                 Console.WriteLine("{0}", key);
  78.                 foreach (var pair in cities[key].OrderByDescending(x=>x.Value))
  79.                 {
  80.                     Console.WriteLine("#  {0} -> {1}", pair.Key, pair.Value);
  81.                 }
  82.             }
  83.  
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement