Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace thePianist
- {
- class thePianist
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, string>> pianist = new Dictionary<string, Dictionary<string, string>>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] arguments = Console.ReadLine().Split("|", StringSplitOptions.RemoveEmptyEntries);
- string piece = arguments[0];
- string composer = arguments[1];
- string key = arguments[2];
- if (!pianist.ContainsKey(piece))
- {
- pianist[piece] = new Dictionary<string, string>();
- pianist[piece].Add(composer, key);
- }
- else if (!pianist.ContainsKey(composer))
- {
- pianist[piece].Add(composer, key);
- }
- }
- string command = string.Empty;
- string composer2 = string.Empty;
- while ((command = Console.ReadLine()) != "Stop")
- {
- string[] arguments = command.Split("|", StringSplitOptions.RemoveEmptyEntries);
- string comandy = arguments[0];
- if (comandy == "Add")
- {
- string piece = arguments[1];
- composer2 = arguments[2];
- string key = arguments[3];
- if (!pianist.ContainsKey(piece))
- {
- pianist[piece] = new Dictionary<string, string>();
- pianist[piece].Add(composer2, key);
- Console.WriteLine($"{piece} by {composer2} in {key} added to the collection!");
- }
- else
- {
- Console.WriteLine($"{piece} is already in the collection!");
- }
- }
- else if (comandy == "Remove")
- {
- string piece = arguments[1];
- if (pianist.ContainsKey(piece))
- {
- pianist.Remove(piece);
- Console.WriteLine($"Successfully removed {piece}!");
- }
- else
- {
- Console.WriteLine($"Invalid operation! {piece} does not exist in the collection.");
- }
- }
- else if (comandy == "ChangeKey")
- {
- string piece = arguments[1];
- string newKey = arguments[2];
- if (pianist.ContainsKey(piece))
- {
- pianist[newKey] = pianist[piece];
- }
- else
- {
- Console.WriteLine($"Invalid operation! {piece} does not exist in the collection.");
- }
- }
- }
- foreach (var item in pianist.OrderBy(x=>x.Key))
- {
- foreach (var kvp in item.Value.OrderBy(x=>x.Key))
- {
- Console.WriteLine($"{item.Key} -> Composer: {kvp.Key}, Key: {kvp.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement