Teo_Yanchev

C# Fundamentals - 02. ShoppingList - 29.02.2020 G2

Oct 29th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._ShoppingList
  6. {
  7. class ShoppingList
  8. {
  9. static void Main()
  10. {
  11.  
  12. List<string> groceriesList = Console.ReadLine().Split('!').ToList();
  13.  
  14. string command = Console.ReadLine();
  15. while (command != "Go Shopping!")
  16. {
  17. string[] currentCommand = command.Split();
  18. string instruction = currentCommand[0];
  19.  
  20. if (instruction == "Urgent")
  21. {
  22. string item = currentCommand[1];
  23.  
  24. if (!groceriesList.Contains(item))
  25. {
  26. groceriesList.Insert(0, item);
  27. }
  28. }
  29.  
  30. else if (instruction == "Unnecessary")
  31. {
  32. string item = currentCommand[1];
  33.  
  34. if (groceriesList.Contains(item))
  35. {
  36. groceriesList.Remove(item);
  37. }
  38. }
  39.  
  40. else if (instruction == "Correct")
  41. {
  42. string oldItem = currentCommand[1];
  43. string newItem = currentCommand[2];
  44.  
  45. if (groceriesList.Contains(oldItem))
  46. {
  47. int index = groceriesList.IndexOf(oldItem);
  48.  
  49. groceriesList.Insert(index, newItem);
  50. groceriesList.RemoveAt(index + 1);
  51. }
  52. }
  53.  
  54. else if (instruction == "Rearrange")
  55. {
  56. string item = currentCommand[1];
  57.  
  58. if (groceriesList.Contains(item))
  59. {
  60. groceriesList.Remove(item);
  61. groceriesList.Add(item);
  62. }
  63. }
  64.  
  65. command = Console.ReadLine();
  66. }
  67.  
  68. Console.WriteLine(string.Join(", ", groceriesList));
  69. }
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment