petarkobakov

The Pianist better code

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