mattnguyen

My Retake Mid Exam 17/08/2021 Problem 2

Aug 17th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Numerics;
  4. using System.Text;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Reflection.Metadata.Ecma335;
  8. using System.Runtime.ExceptionServices;
  9. using System.Threading;
  10. using System.Text.RegularExpressions;
  11.  
  12. namespace ConsoleApp24
  13. {
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. List<string> biscuits = Console.ReadLine().Split(", ").ToList();
  19. string input = Console.ReadLine();
  20.  
  21. while (input != "Eat")
  22. {
  23. string[] commands = input.Split();
  24.  
  25. switch (commands[0])
  26. {
  27. case "Update-Any":
  28. for (int i = 0; i < biscuits.Count-1; i++)
  29. {
  30. if (biscuits[i] == commands[1])
  31. {
  32. string outOfStock = "Out of stock";
  33. biscuits[i] = outOfStock;
  34. }
  35. }
  36. break;
  37. case "Replace":
  38. int indexExtra = int.Parse(commands[2]);
  39. string value = commands[1];
  40. if (indexExtra >= 0 && indexExtra < biscuits.Count)
  41. {
  42. biscuits[indexExtra] = value;
  43. }
  44.  
  45. break;
  46. case "Update-Last":
  47. string last = biscuits[biscuits.Count - 1];
  48. biscuits.Remove(last);
  49. biscuits.Add(commands[1]);
  50.  
  51. break;
  52. case "Rearrange":
  53. if (biscuits.Contains(commands[1]))
  54. {
  55. biscuits.Remove(commands[1]);
  56. biscuits.Add(commands[1]);
  57. }
  58. break;
  59. }
  60.  
  61. input = Console.ReadLine();
  62. }
  63. for (int i = 0; i < biscuits.Count; i++)
  64. {
  65. if (biscuits[i] == "Out of stock")
  66. {
  67. biscuits.Remove("Out of stock");
  68. }
  69. }
  70.  
  71. Console.WriteLine(string.Join(" ", biscuits));
  72.  
  73. }
  74. }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment