petarkobakov

School Library

Jul 2nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace School_Library
  6. {
  7. class Program
  8. {
  9. static void Main(string[] ags)
  10. {
  11. List<string> bookShelf = Console.ReadLine()
  12. .Split('&', StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14. string input = Console.ReadLine();
  15.  
  16. while (input!="Done")
  17. {
  18. string[] command = input.Split(" | ", StringSplitOptions.RemoveEmptyEntries);
  19. string action = command[0];
  20. string bookName = command[1];
  21.  
  22.  
  23. if (action == "Add Book")
  24. if (bookShelf.Contains(bookName))
  25. {
  26. continue;
  27. }
  28. else
  29. {
  30. bookShelf.Insert(0, bookName);
  31. }
  32.  
  33. else if (action == "Take Book")
  34. {
  35. if (bookShelf.Contains(bookName))
  36. {
  37. bookShelf.Remove(bookName);
  38. }
  39. else
  40. {
  41. continue;
  42. }
  43.  
  44. }
  45. else if (action == "Swap Books")
  46. {
  47. string bookName2 = command[2];
  48.  
  49. if (bookShelf.Contains(bookName)&&bookShelf.Contains(bookName2))
  50. {
  51.  
  52. int indexBook1 = bookShelf.IndexOf(bookName);
  53. int indexBook2 = bookShelf.IndexOf(bookName2);
  54.  
  55. string temp = bookShelf[indexBook2];
  56. bookShelf[indexBook2] = bookName;
  57. bookShelf[indexBook1] = temp;
  58.  
  59. }
  60.  
  61. }
  62. else if (action == "Insert Book")
  63. {
  64. bookShelf.Add(bookName);
  65.  
  66. }
  67. else if (action == "Check Book")
  68. {
  69. int index = int.Parse(command[1]);
  70.  
  71. if (index>=0 && index <= bookShelf.Count)
  72. {
  73.  
  74. Console.WriteLine(bookShelf[index]);
  75. }
  76. else
  77. {
  78. input = Console.ReadLine();
  79. continue;
  80. }
  81.  
  82.  
  83. }
  84.  
  85. input = Console.ReadLine();
  86. }
  87. Console.WriteLine(string.Join(", ", bookShelf));
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment