Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace SchoolLibrary
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> books = Console.ReadLine()
- .Split("&")
- .ToList();
- string command = Console.ReadLine();
- while (command != "Done")
- {
- string[] commandToArray = command.Split(" | ").ToArray();
- if (commandToArray[0] == "Add Book")
- {
- books.Insert(0, commandToArray[1]);
- }
- else if (commandToArray[0] == "Take Book")
- {
- for (int i = 0; i < books.Count; i++)
- {
- if (books[i] == commandToArray[1])
- {
- books.Remove(books[i]);
- }
- }
- }
- else if (commandToArray[0] == "Swap Books")
- {
- bool isFirstOnShelf = false;
- bool isSecondOnShelf = false;
- for (int i = 0; i < books.Count; i++)
- {
- int currentPositionFirst = 0;
- int currentPositionSecond = 0;
- if (books[i] == commandToArray[1])
- {
- isFirstOnShelf = true;
- currentPositionFirst = i;
- }
- else if (books[i] == commandToArray[2])
- {
- isSecondOnShelf = true;
- currentPositionSecond = i;
- }
- if (isFirstOnShelf && isSecondOnShelf)
- {
- string temp = books[currentPositionFirst];
- books[currentPositionFirst] = books[currentPositionSecond];
- books[currentPositionSecond] = temp;
- }
- }
- }
- else if (commandToArray[0] == "Insert Book")
- {
- books.Add(commandToArray[1]);
- }
- else if (commandToArray[0] == "Check Book")
- {
- if (int.Parse(commandToArray[1]) >= 0 && int.Parse(commandToArray[1]) < books.Count)
- {
- Console.WriteLine(books[int.Parse(commandToArray[1])]);
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(", ", books));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement