Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace SchoolLibrary
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> books = Console.ReadLine()
  12. .Split("&")
  13. .ToList();
  14.  
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "Done")
  18. {
  19. string[] commandToArray = command.Split(" | ").ToArray();
  20.  
  21. if (commandToArray[0] == "Add Book")
  22. {
  23. books.Insert(0, commandToArray[1]);
  24. }
  25.  
  26. else if (commandToArray[0] == "Take Book")
  27. {
  28. for (int i = 0; i < books.Count; i++)
  29. {
  30. if (books[i] == commandToArray[1])
  31. {
  32. books.Remove(books[i]);
  33. }
  34. }
  35. }
  36.  
  37. else if (commandToArray[0] == "Swap Books")
  38. {
  39. bool isFirstOnShelf = false;
  40. bool isSecondOnShelf = false;
  41.  
  42. for (int i = 0; i < books.Count; i++)
  43. {
  44. int currentPositionFirst = 0;
  45. int currentPositionSecond = 0;
  46.  
  47. if (books[i] == commandToArray[1])
  48. {
  49. isFirstOnShelf = true;
  50. currentPositionFirst = i;
  51. }
  52. else if (books[i] == commandToArray[2])
  53. {
  54. isSecondOnShelf = true;
  55. currentPositionSecond = i;
  56. }
  57. if (isFirstOnShelf && isSecondOnShelf)
  58. {
  59. string temp = books[currentPositionFirst];
  60. books[currentPositionFirst] = books[currentPositionSecond];
  61. books[currentPositionSecond] = temp;
  62. }
  63. }
  64. }
  65.  
  66. else if (commandToArray[0] == "Insert Book")
  67. {
  68. books.Add(commandToArray[1]);
  69. }
  70.  
  71. else if (commandToArray[0] == "Check Book")
  72. {
  73. if (int.Parse(commandToArray[1]) >= 0 && int.Parse(commandToArray[1]) < books.Count)
  74. {
  75. Console.WriteLine(books[int.Parse(commandToArray[1])]);
  76. }
  77. }
  78. command = Console.ReadLine();
  79. }
  80. Console.WriteLine(string.Join(", ", books));
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement