示例#1
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dictionary <string, Pieces> listOfPieces = new Dictionary <string, Pieces>();

            for (int i = 0; i < n; i++)
            {
                string[] input        = Console.ReadLine().Split('|', StringSplitOptions.RemoveEmptyEntries);
                string   pieceName    = input[0];
                string   composerName = input[1];
                string   key          = input[2];

                listOfPieces.Add(pieceName, new Pieces()
                {
                    Piece = pieceName, Composer = composerName, Key = key
                });
            }

            string cmd = String.Empty;

            while ((cmd = Console.ReadLine()) != "Stop")
            {
                string[] cmdArgs = cmd.Split('|', StringSplitOptions.RemoveEmptyEntries);
                string   cmdName = cmdArgs[0];

                switch (cmdName)
                {
                case "Add":
                    Pieces.Add(listOfPieces, cmdArgs);
                    break;

                case "Remove":
                    Pieces.Remove(listOfPieces, cmdArgs);
                    break;

                case "ChangeKey":
                    Pieces.ChangeKey(listOfPieces, cmdArgs);
                    break;
                }
            }

            foreach (var kvp in listOfPieces.OrderBy(x => x.Key).ThenBy(x => x.Value.Composer).ToDictionary(x => x.Key, x => x.Value))
            {
                Console.WriteLine($"{kvp.Key} -> Composer: {kvp.Value.Composer}, Key: {kvp.Value.Key}");
            }
        }