Advertisement
WindFell

Serbian Unleashed

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