Advertisement
WindFell

Serbian Unleashed

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