Advertisement
Guest User

srabsko10

a guest
Feb 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Сръбско_Unleashed10
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, Dictionary<string, long>> citySingers = new Dictionary<string, Dictionary<string, long>>();
  11.             List<string> commands = Console.ReadLine().Split('@',StringSplitOptions.RemoveEmptyEntries).ToList();
  12.             string nameOfCity = "";
  13.             string nameOfSinger = "";
  14.             int tickePrice = 0;
  15.             int countTickets = 0;
  16.             long priceForAllTickets = 0;
  17.  
  18.  
  19.             while (commands[0]!="End")
  20.             {
  21.                 nameOfSinger = commands[0].TrimEnd();
  22.  
  23.                 List<string> helper = commands[1].Split(' ',StringSplitOptions.RemoveEmptyEntries).ToList();
  24.                 helper.Reverse();
  25.                
  26.                 try
  27.                 {
  28.                     countTickets = int.Parse(helper[0]);
  29.                     tickePrice = int.Parse(helper[1]);
  30.                    
  31.                 }
  32.                 catch (Exception)
  33.                 {
  34.                     goto here;
  35.  
  36.                 }
  37.                 priceForAllTickets = countTickets * tickePrice;
  38.  
  39.                 helper.RemoveRange(0, 2);
  40.                 if (helper.Count() == 2)
  41.                 {
  42.                     nameOfCity = helper[1] + " " + helper[0];
  43.                 }
  44.                 else if (helper.Count == 3)
  45.                 {
  46.                     nameOfCity = helper[2] + " " + helper[1] + " " + helper[0];
  47.                 }
  48.                 else
  49.                 {
  50.                     nameOfCity = helper[0];
  51.                 }
  52.  
  53.                 if (!citySingers.ContainsKey(nameOfCity))
  54.                 {
  55.                     Dictionary<string, long> help = new Dictionary<string, long>();
  56.                     help.Add(nameOfSinger, priceForAllTickets);
  57.                     citySingers.Add(nameOfCity, help);
  58.                 }
  59.                 else  
  60.                 {
  61.                     if (!citySingers[nameOfCity].ContainsKey(nameOfSinger))
  62.                     {
  63.                         citySingers[nameOfCity].Add(nameOfSinger, priceForAllTickets);
  64.                     }
  65.                     else
  66.                     {
  67.                         citySingers[nameOfCity][nameOfSinger] += priceForAllTickets;
  68.                     }
  69.                 }
  70.                 here:
  71.                 commands = Console.ReadLine().Split('@').ToList();
  72.             }
  73.  
  74.  
  75.             foreach (var city in citySingers)
  76.             {
  77.                 Console.WriteLine($"{city.Key}");
  78.                 foreach (var singer in city.Value.OrderByDescending(x=>x.Value))
  79.                 {
  80.                     Console.WriteLine($"#  {singer.Key} -> {singer.Value}");
  81.                 }
  82.             }
  83.  
  84.  
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement