mattnguyen

Untitled

Aug 17th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 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> products= Console.ReadLine().Split("|").ToList();
  19. string input = Console.ReadLine();
  20.  
  21. while (input != "Shop!")
  22. {
  23. string[] commands = input.Split("%");
  24.  
  25. switch (commands[0])
  26. {
  27. case "Important":
  28. if (products.Contains(commands[1]))
  29. {
  30. products.Remove(commands[1]);
  31. products.Insert(0, commands[1]);
  32. }
  33. else
  34. {
  35. products.Insert(0, commands[1]);
  36. }
  37. break;
  38. case "Add":
  39. if (!products.Contains(commands[1]))
  40. {
  41. products.Add(commands[1]);
  42. }
  43. else
  44. {
  45. Console.WriteLine("The product is already in the list");
  46. }
  47. break;
  48. case "Swap":
  49.  
  50. if (!products.Contains(commands[1]))
  51. {
  52. Console.WriteLine($"Product {commands[1]} missing!");
  53. }
  54. else if (!products.Contains(commands[2]))
  55. {
  56. Console.WriteLine($"Product {commands[2]} missing!");
  57. }
  58. else
  59. {
  60. var temp = commands[1];
  61. commands[1] = commands[2];
  62. commands[2] = temp;
  63. }
  64.  
  65.  
  66. break;
  67. case "Remove":
  68. if (products.Contains(commands[1]))
  69. {
  70. products.Remove(commands[1]);
  71. }
  72. else
  73. {
  74. Console.WriteLine($"Product {commands[1]} isn't in the list.");
  75. }
  76. break;
  77. case "Reverse":
  78. products.Reverse();
  79. break;
  80. }
  81.  
  82. input = Console.ReadLine();
  83. }
  84.  
  85. for (int i = 0; i < products.Count; i++)
  86. {
  87. Console.WriteLine($"{i+1}. {products[i]}");
  88. }
  89.  
  90. }
  91. }
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment