Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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[] args)
  10. {
  11. List<string> books = Console.ReadLine().Split("&").ToList();
  12.  
  13. string input = Console.ReadLine();
  14. while (input != "Done")
  15. {
  16. string[] tokens = input.Split(" | ");
  17. string command = tokens[0];
  18.  
  19. if (command == "Add Book")
  20. {
  21. string book = tokens[1];
  22. if (!books.Contains(book))
  23. {
  24. books.Insert(0, book);
  25. }
  26. }
  27. else if (command == "Take Book")
  28. {
  29. string book = tokens[1];
  30. if (books.Contains(book))
  31. {
  32. books.Remove(book);
  33. }
  34. }
  35. else if (command == "Swap Books")
  36. {
  37. string firstBook = tokens[1];
  38. string secondBook = tokens[2];
  39. if (books.Contains(firstBook) && books.Contains(secondBook))
  40. {
  41. int index1 = books.IndexOf(firstBook);
  42. int index2 = books.IndexOf(secondBook);
  43. string temp = firstBook;
  44. books[index1] = books[index2];
  45. books[index2] = temp;
  46. }
  47. }
  48. else if (command == "Insert Book")
  49. {
  50. string book = tokens[1];
  51. books.Add(book);
  52. }
  53. else if (command == "Check Book")
  54. {
  55. int index = int.Parse(tokens[1]);
  56. if (index >= 0 && index < books.Count)
  57. {
  58. Console.WriteLine(books[index]);
  59. }
  60. }
  61.  
  62. input = Console.ReadLine();
  63. }
  64.  
  65. Console.WriteLine(String.Join(", ", books));
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement