Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._School_Library
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> booksLibrary = Console.ReadLine().Split('&').ToList();
- string input = Console.ReadLine();
- while (input != "Done")
- {
- string[] spllited = input.Split(" | ");
- if (spllited[0] == "Add Book")
- {
- string bookName = spllited[1];
- if (!booksLibrary.Contains(bookName))
- {
- booksLibrary.Insert(0, bookName); //добавя книга на първа позиция;
- }
- }
- else if (spllited[0] == "Take Book")
- {
- string bookName = spllited[1];
- if (booksLibrary.Contains(bookName))
- {
- booksLibrary.Remove(bookName);
- }
- }
- else if (spllited[0] == "Swap Books")
- {
- string bookName = spllited[1];
- string secondBokk = spllited[2];
- if (booksLibrary.Contains(bookName) && booksLibrary.Contains(secondBokk))
- {
- int indexfirst = booksLibrary.IndexOf(bookName);
- int indexSecond = booksLibrary.IndexOf(secondBokk);
- string temp1 = booksLibrary[indexfirst];
- string temp2 = booksLibrary[indexSecond];
- booksLibrary[indexfirst] = temp2;
- booksLibrary[indexSecond] = temp1;
- }
- }
- else if (spllited[0] == "Insert Book")
- {
- // тук проверката за съдържаща се книга е излишна. Няма условие да се добави, само ако я няма вече в списъка.
- string bookName = spllited[1];
- booksLibrary.Add(bookName);
- }
- else if (spllited[0] == "Check Book")
- {
- int index = int.Parse(spllited[1]);
- if (index >= 0 && index <= booksLibrary.Count)
- {
- Console.WriteLine($"{booksLibrary[index]}");
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine(string.Join(", ", booksLibrary));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement