Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace School_Library
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> books = Console.ReadLine().Split("&").ToList();
- string input = Console.ReadLine();
- while (input != "Done")
- {
- string[] tokens = input.Split(" | ");
- string command = tokens[0];
- if (command == "Add Book")
- {
- string book = tokens[1];
- if (!books.Contains(book))
- {
- books.Insert(0, book);
- }
- }
- else if (command == "Take Book")
- {
- string book = tokens[1];
- if (books.Contains(book))
- {
- books.Remove(book);
- }
- }
- else if (command == "Swap Books")
- {
- string firstBook = tokens[1];
- string secondBook = tokens[2];
- if (books.Contains(firstBook) && books.Contains(secondBook))
- {
- int index1 = books.IndexOf(firstBook);
- int index2 = books.IndexOf(secondBook);
- string temp = firstBook;
- books[index1] = books[index2];
- books[index2] = temp;
- }
- }
- else if (command == "Insert Book")
- {
- string book = tokens[1];
- books.Add(book);
- }
- else if (command == "Check Book")
- {
- int index = int.Parse(tokens[1]);
- if (index >= 0 && index < books.Count)
- {
- Console.WriteLine(books[index]);
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine(String.Join(", ", books));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement