mattnguyen

My Problem 3 (Mid Exam 10/07/2021)

Aug 17th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 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. int index1 = products.IndexOf(commands[1]);
  61. int index2 = products.IndexOf(commands[2]);
  62. string temp = products[index1];
  63. products[index1] = products[index2];
  64. products[index2] = temp;
  65. }
  66.  
  67. break;
  68. case "Remove":
  69. if (products.Contains(commands[1]))
  70. {
  71. products.Remove(commands[1]);
  72. }
  73. else
  74. {
  75. Console.WriteLine($"Product {commands[1]} isn't in the list.");
  76. }
  77. break;
  78. case "Reverse":
  79. products.Reverse();
  80. break;
  81. }
  82.  
  83. input = Console.ReadLine();
  84. }
  85.  
  86. for (int i = 0; i < products.Count; i++)
  87. {
  88. Console.WriteLine($"{i+1}. {products[i]}");
  89. }
  90.  
  91. }
  92. }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment