Advertisement
radostina92

The pianist

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