Advertisement
silvana1303

school library

Jun 13th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Exam
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> books = Console.ReadLine().Split('&').ToList();
  13.  
  14.             List<string> command = Console.ReadLine().Split(" | ").ToList();
  15.  
  16.             while (command[0] != "Done")
  17.             {
  18.                 if (command[0] == "Add Book")
  19.                 {
  20.                     string item = command[1];
  21.  
  22.                     if (!books.Contains(item))
  23.                     {
  24.                         books.Insert(0, item);
  25.                     }
  26.                 }
  27.                 else if (command[0] == "Take Book")
  28.                 {
  29.                     string item = command[1];
  30.  
  31.                     if (books.Contains(item))
  32.                     {
  33.                         books.Remove(item);
  34.                     }
  35.                 }
  36.                 else if (command[0] == "Insert Book")
  37.                 {
  38.                     string item = command[1];
  39.  
  40.                     books.Add(item);
  41.                 }
  42.                 else if (command[0] == "Check Book")
  43.                 {
  44.                     int index = int.Parse(command[1]);
  45.  
  46.                     if (index >= 0 && index < books.Count)
  47.                     {
  48.                         string check = books[index];
  49.  
  50.                         Console.WriteLine(check);
  51.                     }
  52.                 }
  53.                 else if (command[0] == "Swap Books")
  54.                 {
  55.                     string book1 = command[1];
  56.                     string book2 = command[2];
  57.  
  58.                     if (books.Contains(book1) && books.Contains(book2))
  59.                     {
  60.                         int book1Index = books.IndexOf(book1);
  61.                         int book2Index = books.IndexOf(book2);
  62.  
  63.                         books[book1Index] = book2;
  64.                         books[book2Index] = book1;
  65.                     }
  66.                 }
  67.  
  68.                 command = Console.ReadLine().Split(" | ").ToList();
  69.  
  70.             }
  71.  
  72.             Console.WriteLine(string.Join(", ", books));
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement