Advertisement
Guest User

Untitled

a guest
Nov 27th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. using System.IO;
  2. using System.Reflection.Metadata.Ecma335;
  3. using System.Transactions;
  4.  
  5. namespace _03._The_Pianist
  6. {
  7.     class Piece
  8.     {
  9.         public Piece(string pieceName, string composer, string key)
  10.         {
  11.             PieceName = pieceName;
  12.             Composer = composer;
  13.             Key = key;
  14.         }
  15.         public string PieceName { get; set; }
  16.         public string Composer { get; set; }
  17.         public string Key { get; set; }
  18.     }
  19.     internal class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             Dictionary<string, Piece> parts = new Dictionary<string, Piece>();
  24.  
  25.             int n = int.Parse(Console.ReadLine());
  26.  
  27.             for (int i = 0; i < n; i++)
  28.             {
  29.                 string[] input = Console.ReadLine().Split("|").ToArray();
  30.  
  31.                 string pieceName = input[0];
  32.                 string composer = input[1];
  33.                 string key = input[2];
  34.                 Piece piece = new Piece(pieceName, composer, key);
  35.                 if (!parts.ContainsKey(pieceName))
  36.                 {
  37.                     parts.Add(pieceName, piece);
  38.                 }
  39.  
  40.                 parts[pieceName].Composer = composer;
  41.                 parts[pieceName].Key = key;
  42.             }
  43.             string inp;
  44.             while ((inp = Console.ReadLine()) != "Stop")
  45.             {
  46.                 string[] data = inp.Split("|").ToArray();
  47.                 string command = data[0];
  48.  
  49.                 if (command == "Add")
  50.                 {
  51.                     string pieceName = data[1];
  52.                     string composer = data[2];
  53.                     string key = data[3];
  54.  
  55.                     if (parts.ContainsKey(pieceName))
  56.                     {
  57.                         Console.WriteLine($"{pieceName} is already in the collection!");
  58.                         continue;
  59.                     }
  60.                     else
  61.                     {
  62.                         Piece piece = new Piece(pieceName, composer, key);
  63.                         parts.Add(pieceName, piece);
  64.                         Console.WriteLine($"{pieceName} by {composer} in {key} added to the collection!");
  65.                     }
  66.                 }
  67.                 else if (command == "Remove")
  68.                 {
  69.                     string piece = data[1];
  70.  
  71.                     if (!parts.ContainsKey(piece))
  72.                     {
  73.                         Console.WriteLine($"Invalid operation! {piece} does not exist in the collection.");
  74.                         continue;
  75.                     }
  76.                     else
  77.                     {
  78.                         parts.Remove(piece);
  79.                         Console.WriteLine($"Successfully removed {piece}!");
  80.                     }
  81.                 }
  82.                 else if (command.Equals("ChangeKey"))
  83.                 {
  84.                     string piece = data[1];
  85.                     string newKey = data[2];
  86.  
  87.                     if (parts.ContainsKey(piece))
  88.                     {
  89.                         parts[piece].Key = newKey;
  90.                         Console.WriteLine($"Changed the key of {piece} to {newKey}!");
  91.                         continue;
  92.                     }
  93.                     else
  94.                     {
  95.                         Console.WriteLine($"Invalid operation! {piece} does not exist in the collection.");
  96.  
  97.                     }
  98.                 }
  99.             }
  100.  
  101.             foreach (var piece in parts)
  102.             {
  103.                 Console.WriteLine($"{piece.Value.PieceName} -> Composer: {piece.Value.Composer}, Key: {piece.Value.Key}");
  104.             }
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement