Advertisement
Guest User

Srabsko

a guest
Mar 4th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ExamPreparation
  8. {
  9.     public class Venue
  10.     {
  11.         public Venue(string name)
  12.         {
  13.             this.Name = name;
  14.             this.Singers = new List<Singer>();
  15.         }
  16.  
  17.         public string Name { get; private set; }
  18.  
  19.         public List<Singer> Singers { get; set; }
  20.  
  21.         public override string ToString()
  22.         {
  23.             StringBuilder output = new StringBuilder();
  24.             output.AppendLine(this.Name);
  25.  
  26.             foreach (var singer in this.Singers.OrderByDescending(s => s.Money))
  27.             {
  28.                 output.AppendLine($"#  {singer}");
  29.             }
  30.  
  31.             return output.ToString().Trim();
  32.         }
  33.     }
  34.  
  35.     public class Singer
  36.     {
  37.         public Singer(string name, long money)
  38.         {
  39.             this.Name = name;
  40.             this.Money = money;
  41.         }
  42.  
  43.         public string Name { get; private set; }
  44.  
  45.         public long Money { get; set; }
  46.  
  47.         public override string ToString()
  48.         {
  49.             return $"{this.Name} -> {this.Money}";
  50.         }
  51.     }
  52.  
  53.     public class Startup
  54.     {
  55.         public static void Main()
  56.         {
  57.             string input = Console.ReadLine();
  58.             string pattern = @"((?:.*?)\s{1,3})@((?:.*?)\s{1,3})(\d+) (\d+)";
  59.             Regex regex = new Regex(pattern);
  60.             Dictionary<string, Venue> tableInfo = new Dictionary<string, Venue>();
  61.  
  62.             while (input != "End")
  63.             {
  64.                 Match match = regex.Match(input);
  65.  
  66.                 if (match.Success)
  67.                 {
  68.                     string singerName = match.Groups[1].Value.Trim();
  69.                     string venue = match.Groups[2].Value.Trim();
  70.                     long ticketsPrice = long.Parse(match.Groups[3].Value.Trim());
  71.                     long ticketsCount = long.Parse(match.Groups[4].Value.Trim());
  72.                     long totalMoney = ticketsCount * ticketsPrice;
  73.  
  74.                     if (tableInfo.ContainsKey(venue))
  75.                     {
  76.                         if (tableInfo[venue].Singers.Any(s => s.Name == singerName))
  77.                         {
  78.                             tableInfo[venue].Singers.Find(s => s.Name == singerName).Money += totalMoney;
  79.                         }
  80.                         else
  81.                         {
  82.                             tableInfo[venue].Singers.Add(new Singer(singerName, totalMoney));
  83.                         }
  84.                     }
  85.                     else
  86.                     {
  87.                         tableInfo.Add(venue, new Venue(venue));
  88.                         tableInfo[venue].Singers.Add(new Singer(singerName, totalMoney));
  89.                     }
  90.                 }
  91.  
  92.                 input = Console.ReadLine();
  93.             }
  94.  
  95.             foreach (var item in tableInfo)
  96.             {
  97.                 Console.WriteLine(item.Value);
  98.             }
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement