Advertisement
Guest User

Untitled

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