Advertisement
WindFell

Serbian Unleashed

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