petarkobakov

Shopping List

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