Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._School_Library
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> booksLibrary = Console.ReadLine().Split('&').ToList();
  12. string input = Console.ReadLine();
  13.  
  14. while (input != "Done")
  15. {
  16. string[] spllited = input.Split(" | ");
  17. if (spllited[0] == "Add Book")
  18. {
  19. string bookName = spllited[1];
  20. if (!booksLibrary.Contains(bookName))
  21. {
  22. booksLibrary.Insert(0, bookName); //добавя книга на първа позиция;
  23. }
  24. }
  25. else if (spllited[0] == "Take Book")
  26. {
  27. string bookName = spllited[1];
  28. if (booksLibrary.Contains(bookName))
  29. {
  30. booksLibrary.Remove(bookName);
  31. }
  32. }
  33. else if (spllited[0] == "Swap Books")
  34. {
  35. string bookName = spllited[1];
  36. string secondBokk = spllited[2];
  37. if (booksLibrary.Contains(bookName) && booksLibrary.Contains(secondBokk))
  38. {
  39. int indexfirst = booksLibrary.IndexOf(bookName);
  40. int indexSecond = booksLibrary.IndexOf(secondBokk);
  41. string temp1 = booksLibrary[indexfirst];
  42. string temp2 = booksLibrary[indexSecond];
  43. booksLibrary[indexfirst] = temp2;
  44. booksLibrary[indexSecond] = temp1;
  45.  
  46. }
  47. }
  48. else if (spllited[0] == "Insert Book")
  49. {
  50. // тук проверката за съдържаща се книга е излишна. Няма условие да се добави, само ако я няма вече в списъка.
  51. string bookName = spllited[1];
  52. booksLibrary.Add(bookName);
  53. }
  54. else if (spllited[0] == "Check Book")
  55. {
  56. int index = int.Parse(spllited[1]);
  57. if (index >= 0 && index <= booksLibrary.Count)
  58. {
  59. Console.WriteLine($"{booksLibrary[index]}");
  60. }
  61. }
  62. input = Console.ReadLine();
  63. }
  64. Console.WriteLine(string.Join(", ", booksLibrary));
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement