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.Threading.Tasks;
- using System.Numerics;
- namespace ConsoleApp14
- {
- class Program
- {
- static void Main(string[] args)
- {
- var cities = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input=="End")
- {
- break;
- }
- string[] inputToArray = input.Split('@').ToArray();
- if (inputToArray.Length == 2)
- {
- //artist name
- string[] artistToArray = inputToArray[0].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string artist = string.Empty;
- if (artistToArray.Length <= 3)
- {
- artist = string.Join(" ", artistToArray);
- }
- else
- {
- continue;
- }
- //sumPrice
- List<string> cityAndPrice = inputToArray[1].Split().ToList();
- if (cityAndPrice.Count<3)
- {
- continue;
- }
- int ticketsCount = int.Parse(cityAndPrice[cityAndPrice.Count - 1]);
- cityAndPrice.RemoveAt(cityAndPrice.Count-1);
- int ticketsPrice = int.Parse(cityAndPrice[cityAndPrice.Count - 1]);
- cityAndPrice.RemoveAt(cityAndPrice.Count - 1);
- int sum = ticketsCount * ticketsPrice;
- //city name
- string city = string.Empty;
- if (cityAndPrice.Count<=3)
- {
- city = string.Join(" ", cityAndPrice);
- }
- else
- {
- continue;
- }
- //add in the dictionary
- if (!cities.ContainsKey(city))
- {
- cities.Add(city, new Dictionary<string, int>());
- }
- if (!cities[city].ContainsKey(artist))
- {
- cities[city].Add(artist, 0);
- }
- cities[city][artist] += sum;
- }
- }
- foreach (var key in cities.Keys)
- {
- Console.WriteLine("{0}", key);
- foreach (var pair in cities[key].OrderByDescending(x=>x.Value))
- {
- Console.WriteLine("# {0} -> {1}", pair.Key, pair.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement