Advertisement
LardaX

Сръбско-Unleashed

Oct 10th, 2016
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 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.  
  7. namespace Сръбско_Unleashed
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, long>> cityProfit = new Dictionary<string, Dictionary<string, long>>();
  14.  
  15.             string[] singerInfo = ReadInfo();
  16.  
  17.             while (!singerInfo[0].Equals("End"))
  18.             {
  19.  
  20.                 if (!singerInfo[0][singerInfo[0].Length - 1].Equals(' '))
  21.                 {
  22.                     singerInfo = ReadInfo();
  23.                 }
  24.                 else
  25.                 {
  26.                     string[] leftPart = singerInfo[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  27.                     string[] rightPart = singerInfo[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  28.                     string singer = string.Join(" ", leftPart);
  29.  
  30.  
  31.                     if (rightPart.Length - 2 > 0)
  32.                     {
  33.                         string[] cityAsString = new string[rightPart.Length - 2];
  34.  
  35.                         for (int i = 0; i < cityAsString.Length; i++)
  36.                         {
  37.                             cityAsString[i] = rightPart[i];
  38.                         }
  39.  
  40.                         int ticketPrice, ticketCount;
  41.                         long profit;
  42.  
  43.                         if (int.TryParse(rightPart[rightPart.Length - 1], out ticketCount) &&
  44.                             int.TryParse(rightPart[rightPart.Length - 2], out ticketPrice))
  45.                         {
  46.                             profit = ticketPrice * ticketCount;
  47.                             string newCity = string.Join(" ", cityAsString);
  48.                             InsertCity(cityProfit, newCity);
  49.                             InsertProfit(cityProfit, newCity, singer, profit);
  50.                             singerInfo = ReadInfo();
  51.                         }
  52.                         else
  53.                         {
  54.                             singerInfo = ReadInfo();
  55.                         }
  56.  
  57.                     }
  58.                     else
  59.                     {
  60.                         singerInfo = ReadInfo();
  61.                     }
  62.                 }
  63.             }
  64.  
  65.             PrintProfit(cityProfit);
  66.         }
  67.  
  68.         private static string[] ReadInfo()
  69.         {
  70.             string[] singerInfo = Console.ReadLine().Split('@').ToArray();
  71.             return singerInfo;
  72.         }
  73.  
  74.         private static void PrintProfit(Dictionary<string, Dictionary<string, long>> cityProfit)
  75.         {
  76.             foreach (KeyValuePair<string, Dictionary<string, long>> cityEntry in cityProfit)
  77.             {
  78.                 Console.WriteLine(cityEntry.Key);
  79.  
  80.                 foreach (KeyValuePair<string, long> singerProfit in cityEntry.Value.OrderByDescending(x => x.Value))
  81.                 {
  82.                     Console.WriteLine($"#  {singerProfit.Key} -> {singerProfit.Value}");
  83.                 }
  84.             }
  85.         }
  86.  
  87.         private static void InsertProfit(Dictionary<string, Dictionary<string, long>> cityProfit, string newCity, string singer, long profit)
  88.         {
  89.             if (!cityProfit[newCity].ContainsKey(singer))
  90.             {
  91.                 cityProfit[newCity].Add(singer, 0);
  92.             }
  93.             cityProfit[newCity][singer] += profit;
  94.         }
  95.  
  96.         private static void InsertCity(Dictionary<string, Dictionary<string, long>> cityProfit, string newCity)
  97.         {
  98.             if (!cityProfit.ContainsKey(newCity))
  99.             {
  100.                 cityProfit.Add(newCity, new Dictionary<string, long>());
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement