Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.ListOperations
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. List<int> list = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13. while (true)
  14. {
  15. string[] command = Console.ReadLine().Split().ToArray();
  16.  
  17. if (command[0] == "End")
  18. {
  19. break;
  20. }
  21. else if (command[0] == "Add")
  22. {
  23. list.Add(int.Parse(command[1]));
  24. }
  25. else if (command[0] == "Insert")
  26. {
  27. if (int.Parse(command[2]) >= list.Count || int.Parse(command[2]) < 0)
  28. {
  29. Console.WriteLine("Invalid index");
  30. }
  31. else
  32. {
  33. list.Insert(int.Parse(command[2]), int.Parse(command[1]));
  34. }
  35. }
  36. else if (command[0] == "Remove")
  37. {
  38. if (int.Parse(command[1]) >= list.Count || int.Parse(command[1]) < 0)
  39. {
  40. Console.WriteLine("Invalid index");
  41. }
  42. else
  43. {
  44. list.RemoveAt(int.Parse(command[1]));
  45. }
  46. }
  47. else if (command[1] == "left")
  48. {
  49. for (int i = 0; i < int.Parse(command[2]); i++)
  50. {
  51. int save = list[0];
  52. list.RemoveAt(0);
  53. list.Add(save);
  54. }
  55. }
  56. else if (command[1] == "right")
  57. {
  58. for (int i = 0; i < int.Parse(command[2]); i++)
  59. {
  60. int save = list[list.Count];
  61. list.RemoveAt(list.Count);
  62. list.Insert(0, save);
  63. }
  64. }
  65. }
  66.  
  67. Console.WriteLine(string.Join(' ', list));
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement