Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07b_Dictionaries_Lambda_Expressions_LINQ_Exercises
- {
- class Dictionaries_Lambda_Expressions_LINQ_Exercises
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, long>> lineUp = new Dictionary<string, Dictionary<string, long>>();
- while (true)
- {
- string[] input = Console.ReadLine().Split(new char[] { '@' }).ToArray();
- if (input[0].Equals("End"))
- {
- break;
- }
- string artistName = input[0].Trim();
- string[] concertTicketsAndMoney = input[1].Split();
- if (concertTicketsAndMoney.Length < 3 || !input[0].EndsWith(" "))
- {
- continue;
- }
- int ticketsCount = 0;
- int ticketsPrice = 0;
- try
- {
- ticketsCount = int.Parse(concertTicketsAndMoney[concertTicketsAndMoney.Length - 1]);
- ticketsPrice = int.Parse(concertTicketsAndMoney[concertTicketsAndMoney.Length - 2]);
- }
- catch
- {
- continue;
- }
- string venue = "";
- for (int i = 0; i < concertTicketsAndMoney.Length - 2; i++)
- {
- venue += concertTicketsAndMoney[i] + " ";
- }
- venue = venue.TrimEnd();
- if (!lineUp.ContainsKey(venue))
- {
- lineUp.Add(venue, new Dictionary<string, long>());
- }
- if (!lineUp[venue].ContainsKey(artistName))
- {
- lineUp[venue].Add(artistName, 0);
- }
- lineUp[venue][artistName] += (long)ticketsPrice * ticketsCount;
- }
- foreach (var venue in lineUp)
- {
- Console.WriteLine(venue.Key);
- foreach (var singer in lineUp[venue.Key].OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"# {singer.Key} -> {singer.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement