Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Encapsulation
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> biscuits = Console.ReadLine()
- .Split(", ", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- string command = Console.ReadLine();
- while (command != "Eat")
- {
- string[] cmdArgs = command.Split();
- if (cmdArgs[0] == "Update-Any")
- {
- for (int i = 0; i < biscuits.Count; i++)
- {
- if (biscuits[i] == cmdArgs[1])
- {
- biscuits[i] = "Out of stock";
- }
- }
- }
- else if (cmdArgs[0] == "Remove")
- {
- int index = int.Parse(cmdArgs[2]);
- if (index >= 0 && index < biscuits.Count)
- {
- biscuits[index] = cmdArgs[1];
- }
- }
- else if (cmdArgs[0] == "Update-Last")
- {
- biscuits[biscuits.Count - 1] = cmdArgs[1];
- }
- else if (cmdArgs[0] == "Rearrange")
- {
- if (biscuits.Contains(cmdArgs[1]))
- {
- biscuits.Remove(cmdArgs[1]);
- biscuits.Add(cmdArgs[1]);
- }
- }
- command = Console.ReadLine();
- }
- List<string> output = biscuits.Where(x => x != "Out of stock").ToList();
- Console.WriteLine(string.Join(" ",output));
- }
- }
- }
Add Comment
Please, Sign In to add comment