Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ExamPreparation
- {
- public class Venue
- {
- public Venue(string name)
- {
- this.Name = name;
- this.Singers = new List<Singer>();
- }
- public string Name { get; private set; }
- public List<Singer> Singers { get; set; }
- public override string ToString()
- {
- StringBuilder output = new StringBuilder();
- output.AppendLine(this.Name);
- foreach (var singer in this.Singers.OrderByDescending(s => s.Money))
- {
- output.AppendLine($"# {singer}");
- }
- return output.ToString().Trim();
- }
- }
- public class Singer
- {
- public Singer(string name, long money)
- {
- this.Name = name;
- this.Money = money;
- }
- public string Name { get; private set; }
- public long Money { get; set; }
- public override string ToString()
- {
- return $"{this.Name} -> {this.Money}";
- }
- }
- public class Startup
- {
- public static void Main()
- {
- string input = Console.ReadLine();
- string pattern = @"((?:.*?)\s{1,3})@((?:.*?)\s{1,3})(\d+) (\d+)";
- Regex regex = new Regex(pattern);
- Dictionary<string, Venue> tableInfo = new Dictionary<string, Venue>();
- while (input != "End")
- {
- Match match = regex.Match(input);
- if (match.Success)
- {
- string singerName = match.Groups[1].Value.Trim();
- string venue = match.Groups[2].Value.Trim();
- long ticketsPrice = long.Parse(match.Groups[3].Value.Trim());
- long ticketsCount = long.Parse(match.Groups[4].Value.Trim());
- long totalMoney = ticketsCount * ticketsPrice;
- if (tableInfo.ContainsKey(venue))
- {
- if (tableInfo[venue].Singers.Any(s => s.Name == singerName))
- {
- tableInfo[venue].Singers.Find(s => s.Name == singerName).Money += totalMoney;
- }
- else
- {
- tableInfo[venue].Singers.Add(new Singer(singerName, totalMoney));
- }
- }
- else
- {
- tableInfo.Add(venue, new Venue(venue));
- tableInfo[venue].Singers.Add(new Singer(singerName, totalMoney));
- }
- }
- input = Console.ReadLine();
- }
- foreach (var item in tableInfo)
- {
- Console.WriteLine(item.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement