Advertisement
petarkobakov

The Pianist

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