petaryankov00

Demo

Mar 6th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Encapsulation
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> biscuits = Console.ReadLine()
  12.                 .Split(", ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .ToList();
  14.  
  15.             string command = Console.ReadLine();
  16.  
  17.             while (command != "Eat")
  18.             {
  19.                 string[] cmdArgs = command.Split();
  20.                 if (cmdArgs[0] == "Update-Any")
  21.                 {
  22.                     for (int i = 0; i < biscuits.Count; i++)
  23.                     {
  24.                         if (biscuits[i] == cmdArgs[1])
  25.                         {
  26.                             biscuits[i] = "Out of stock";
  27.                         }
  28.                     }
  29.                    
  30.                 }
  31.                 else if (cmdArgs[0] == "Remove")
  32.                 {
  33.                     int index = int.Parse(cmdArgs[2]);
  34.                     if (index >= 0 && index < biscuits.Count)
  35.                     {
  36.                         biscuits[index] = cmdArgs[1];
  37.                     }
  38.                 }
  39.                 else if (cmdArgs[0] == "Update-Last")
  40.                 {
  41.                     biscuits[biscuits.Count - 1] = cmdArgs[1];
  42.                 }
  43.                 else if (cmdArgs[0] == "Rearrange")
  44.                 {
  45.                     if (biscuits.Contains(cmdArgs[1]))
  46.                     {
  47.                         biscuits.Remove(cmdArgs[1]);
  48.                         biscuits.Add(cmdArgs[1]);
  49.                     }
  50.                 }
  51.  
  52.                 command = Console.ReadLine();
  53.             }
  54.  
  55.             List<string> output = biscuits.Where(x => x != "Out of stock").ToList();
  56.             Console.WriteLine(string.Join(" ",output));
  57.         }
  58.     }
  59. }
  60.  
Add Comment
Please, Sign In to add comment