Stan0033

Untitled

Jun 24th, 2021
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace apps
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. //list operations
  12.  
  13. List<int> integers = Get().Split(' ').Select(int.Parse).ToList();
  14.  
  15.  
  16. for (int i = 0; i < integers.Count - 1; i++)
  17. {
  18. string[] command = Get().Split(' ');
  19. if (command[0] == "End")
  20. {
  21. break;
  22. }
  23. else
  24. {
  25. if (command[0] == "Add")
  26. {
  27. integers.Add(Convert.ToInt32(command[1])); continue;
  28. }
  29. if (command[0] == "Insert")
  30. {
  31. int index = Convert.ToInt32(command[2]);
  32. if (index > integers.Count ||index<0 ) { Console.WriteLine("Invalid index"); continue; }
  33. int number = Convert.ToInt32(command[1]);
  34. integers.Insert(index, number); continue;
  35. }
  36. if (command[0] == "Remove")
  37. {
  38. int index = Convert.ToInt32(command[1]);
  39. if (index > integers.Count || index<0) { Console.WriteLine("Invalid index"); continue; }
  40. integers.RemoveAt(index); continue;
  41. }
  42. if (command[1] == "left")
  43. {
  44. int times = Convert.ToInt32(command[2]);
  45. for (int x =1; x<=times; x++)
  46. {
  47. int firstElement = integers[0];
  48. integers.Add(firstElement);
  49. integers.RemoveAt(0);
  50. }
  51.  
  52. continue;
  53. }
  54. if (command[1] == "right")
  55. {
  56. int times = Convert.ToInt32(command[2]);
  57. for (int x =1; x <= times; x++)
  58. {
  59. int lastlement = integers[integers.Count-1];
  60. integers.Insert(0, lastlement);
  61. integers.RemoveAt(integers.Count - 1);
  62. }
  63. continue;
  64. }
  65.  
  66. }
  67. }
  68.  
  69. Console.WriteLine(string.Join(" ", integers));
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. static string Get() { return Console.ReadLine(); }
  77.  
  78. }
  79. }
  80.  
  81. }
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment