WindFell

Serbian Unleashed

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