Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. namespace _10._Сръбско_Unleashed
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class СръбскоUnleashed
  9.     {
  10.         public static void Main()
  11.         {
  12.             var data = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             string input;
  15.             while ((input = Console.ReadLine()) != "End")
  16.             {
  17.                 string pattern = @"(([A-Za-z]+\s){1,3})@(([A-Za-z]+\s){1,3})(\d+)\s(\d+)";
  18.  
  19.                 if (Regex.IsMatch(input, pattern))
  20.                 {
  21.                     var match = Regex.Match(input, pattern);
  22.  
  23.                     string singer = match.Groups[1].Value.Trim();
  24.                     string album = match.Groups[3].Value.Trim();
  25.                     int ticketPrice = int.Parse(match.Groups[5].Value);
  26.                     int ticketCount = int.Parse(match.Groups[6].Value);
  27.  
  28.                     int totalPrise = ticketCount * ticketPrice;
  29.  
  30.                     if (!data.ContainsKey(album))
  31.                     {
  32.                         data.Add(album, new Dictionary<string, int>());
  33.                     }
  34.                     if (!data[album].ContainsKey(singer))
  35.                     {
  36.                         data[album].Add(singer, 0);
  37.                     }
  38.  
  39.                     data[album][singer] += totalPrise;
  40.                 }
  41.             }
  42.  
  43.             foreach (var kvp in data)
  44.             {
  45.                 Console.WriteLine($"{kvp.Key}");
  46.  
  47.                 foreach (var artist in kvp.Value.OrderByDescending(p => p.Value))
  48.                 {
  49.                     Console.WriteLine($"#  {artist.Key} -> {artist.Value}");
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement