Advertisement
Guest User

Untitled

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