Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SrabskoUnleashed
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- class Program
- {
- const string pattern = @"([a-zA-Z]+\s){1,3}@([a-zA-Z0-9]+\s){1,3}[0-9]+\s[0-9]+";
- static void Main()
- {
- Dictionary<string, List<Singer>> venues = new Dictionary<string, List<Singer>>();
- string input = Console.ReadLine();
- while (input != "End")
- {
- var matches = Regex.Matches(input, pattern);
- if (matches.Count > 0)
- {
- string line = matches[0].Value;
- string[] split = line.Split('@');
- string name = split[0].Trim();
- string[] secondSplit = split[1].Split(' ');
- int ticketsCount = int.Parse(secondSplit.Last());
- int ticketsPrice = int.Parse(secondSplit[secondSplit.Length - 2]);
- string place = secondSplit[0];
- for (int i = 1; i < secondSplit.Length - 2; i++)
- {
- place += " " + secondSplit[i];
- }
- Singer singer = new Singer(name, ticketsCount * ticketsPrice);
- if (!venues.ContainsKey(place))
- {
- venues.Add(place, new List<Singer>());
- }
- if (venues[place].Contains(singer))
- {
- var contained = venues[place].First(s => s.Name == singer.Name);
- contained.TotalMoney += singer.TotalMoney;
- }
- else
- {
- venues[place].Add(singer);
- }
- }
- input = Console.ReadLine();
- }
- foreach (var pair in venues)
- {
- pair.Value.Sort();
- Console.WriteLine(pair.Key);
- foreach (var singer in pair.Value)
- {
- Console.WriteLine("# {0} -> {1}", singer.Name, singer.TotalMoney);
- }
- }
- }
- }
- class Singer : IComparable
- {
- public string Name { get; set; }
- public int TotalMoney { get; set; }
- public Singer(string name, int money)
- {
- this.Name = name;
- this.TotalMoney = money;
- }
- public int CompareTo(object obj)
- {
- return -(this.TotalMoney.CompareTo((obj as Singer).TotalMoney));
- }
- public override bool Equals(object obj)
- {
- return this.Name.Equals((obj as Singer).Name);
- }
- public override int GetHashCode()
- {
- return this.Name.GetHashCode();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement