viraco4a

Untitled

Dec 19th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace task_27
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> list = Console.ReadLine()
  14. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(s => int.Parse(s))
  16. .ToList();
  17. for (int i = 0; ; i++)
  18. {
  19. List<string> input = Console.ReadLine()
  20. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  21. .ToList();
  22. if (input.Contains("add") && !input.Contains("addMany"))
  23. {
  24. int index = int.Parse(input[1]);
  25. int element = int.Parse(input[2]);
  26. list.Add(list[list.Count - 1]);
  27. for (int j = list.Count - 1; j > index; j--)
  28. {
  29. list[j] = list[j - 1];
  30. }
  31. list[index] = element;
  32. }
  33. if (input.Contains("addMany"))
  34. {
  35. int index = int.Parse(input[1]);
  36. int[] element = new int[input.Count - 2];
  37.  
  38. for (int j = 0; j < element.Length; j++)
  39. {
  40. element[j] = int.Parse(input[j + 2]);
  41. }
  42. for (int j = element.Length; j > 0; j--)
  43. {
  44. list.Add(0);
  45. }
  46. for (int j = list.Count - 1; j >= index + element.Length; j--)
  47. {
  48. list[j] = list[j - element.Length];
  49. }
  50. int k = 0;
  51. for (int j = index; j < index + element.Length; j++, k++)
  52. {
  53. list[j] = element[k];
  54. }
  55. }
  56. if (input.Contains("contains"))
  57. {
  58. int element = int.Parse(input[1]);
  59. bool exist = false;
  60. for (int j = 0; j < list.Count; j++)
  61. {
  62. if (list[j] == element)
  63. {
  64. exist = true;
  65. Console.WriteLine(j);
  66. break;
  67. }
  68. }
  69. if (exist == false)
  70. {
  71. Console.WriteLine(-1);
  72. }
  73. }
  74. if (input.Contains("remove"))
  75. {
  76. int index = int.Parse(input[1]);
  77. list.RemoveAt(index);
  78. }
  79. if (input.Contains("shift"))
  80. {
  81. int position = int.Parse(input[1]);
  82. for (int j = 0; j < position; j++)
  83. {
  84. list.Add(0);
  85. }
  86. for (int j = 0; j < position; j++)
  87. {
  88. list[j + list.Count - position] = list[j];
  89. }
  90. list.RemoveRange(0, position);
  91. }
  92. if (input.Contains("sumPairs"))
  93. {
  94. if (list.Count % 2 != 0)
  95. {
  96. list.Add(0);
  97. }
  98. for (int j = 0; j < list.Count; j += 2)
  99. {
  100. list[j] = list[j] + list[j + 1];
  101. }
  102. for (int j = list.Count - 1; j > 0; j -= 2)
  103. {
  104. list.RemoveAt(j);
  105. }
  106. }
  107. if (input.Contains("print"))
  108. {
  109. Console.WriteLine("[" + string.Join(", ", list) + "]");
  110. break;
  111. }
  112. }
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment