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