Advertisement
vilangelova

04.List Operations

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