Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- List<string> books = Console.ReadLine().Split('&').ToList();
- List<string> command = Console.ReadLine().Split(" | ").ToList();
- while (command[0] != "Done")
- {
- if (command[0] == "Add Book")
- {
- string item = command[1];
- if (!books.Contains(item))
- {
- books.Insert(0, item);
- }
- }
- else if (command[0] == "Take Book")
- {
- string item = command[1];
- if (books.Contains(item))
- {
- books.Remove(item);
- }
- }
- else if (command[0] == "Insert Book")
- {
- string item = command[1];
- books.Add(item);
- }
- else if (command[0] == "Check Book")
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < books.Count)
- {
- string check = books[index];
- Console.WriteLine(check);
- }
- }
- else if (command[0] == "Swap Books")
- {
- string book1 = command[1];
- string book2 = command[2];
- if (books.Contains(book1) && books.Contains(book2))
- {
- int book1Index = books.IndexOf(book1);
- int book2Index = books.IndexOf(book2);
- books[book1Index] = book2;
- books[book2Index] = book1;
- }
- }
- command = Console.ReadLine().Split(" | ").ToList();
- }
- Console.WriteLine(string.Join(", ", books));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement