WindFell

Serbian Unleashed

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