Onedimensional arrays
Onedimensional arrays: creation
Array1. Given an integer N (> 0), create and output an array of N integers that are the first positive odd numbers: 1, 3, 5, … .
Array2. Given an integer N (> 0), create and output an array of N integers that are the first positive integer powers of 2: 2, 4, 8, 16, … .
Array3. An integer N (> 1), the first term A and the common difference D of an arithmetic sequence are given (A and D are real numbers). Create and output an array of N real numbers that are the initial terms of this sequence: A, A + D, A + 2·D, A + 3·D, … .
Array4°. An integer N (> 1), the first term A and the common ratio R of a geometric sequence are given (A and D are real numbers). Create and output an array of N real numbers that are the initial terms of this sequence: A, A·R, A·R^{2}, A·R^{3}, … .
Array5. Given an integer N (> 2), create and output an array of N integers that are the initial terms of a sequence {F_{K}} of the Fibonacci numbers: F_{1} = 1, F_{2} = 1, F_{K} = F_{K−2} + F_{K−1}, K = 3, 4, … .
Array6. Given three integers N (> 2), A, B, create and output an array of N integers such that the first element is equal to A, the second one is equal to B, and each subsequent element is equal to the sum of all previous ones.
Onedimensional arrays: output of elements
Array7°. Given an array of N real numbers, output its elements in inverse order.
Array8. Given an array of N integers, output all odd numbers contained in the array in ascending order of their indices. Also output the amount K of odd numbers contained in the array.
Array9. Given an array of N integers, output all even numbers contained in the array in descending order of their indices. Also output the amount K of even numbers contained in the array.
Array10. Given an array of N integers, output all even numbers contained in the array in ascending order of their indices and then output all odd numbers contained in the array in descending order of their indices.
Array11. An array A of N real numbers and an integer K (1 ≤ K ≤ N) are given. Output array elements with order numbers that are multiples of K: A_{K}, A_{2·K}, A_{3·K}, … . Do not use conditional statements.
Array12. An array A of N real numbers is given (N is an even number). Output array elements with even order numbers in ascending order of indices: A_{2}, A_{4}, A_{6}, …, A_{N}. Do not use conditional statements.
Array13. An array A of N real numbers is given (N is an odd number). Output array elements with odd order numbers in descending order of indices: A_{N}, A_{N−2}, A_{N−4}, …, A_{1}. Do not use conditional statements.
Array14. An array A of N real numbers is given. Output array elements with even order numbers (in ascending order of indices) and then output array elements with odd order numbers (in ascending order of indices too): A_{2}, A_{4}, A_{6}, …, A_{1}, A_{3}, A_{5}, … . Do not use conditional statements.
Array15. An array A of N real numbers is given. Output array elements with odd order numbers in ascending order of indices and then output array elements with even order numbers in descending order of indices: A_{1}, A_{3}, A_{5}, …, A_{6}, A_{4}, A_{2}. Do not use conditional statements.
Array16°. An array A of N real numbers is given. Output array elements as follows: A_{1}, A_{N}, A_{2}, A_{N−1}, A_{3}, A_{N−2}, … .
Array17. An array A of N real numbers is given. Output array elements as follows: A_{1}, A_{2}, A_{N}, A_{N−1}, A_{3}, A_{4}, A_{N−2}, A_{N−3}, … .
Onedimensional arrays: analysis of elements
Array18. An array A of 10 nonzero integers is given. Output the value of the first element A_{K} that satisfies the following inequality: A_{K} < A_{10}. If the array does not contain such elements then output 0.
Array19. An array A of 10 integers is given. Output the order number of the last element A_{K} that satisfies the following double inequality: A_{1} < A_{K} < A_{10}. If the array does not contain such elements then output 0.
Array20. An array of N real numbers and two integers K and L (1 ≤ K ≤ L ≤ N) are given. Find the sum of array elements with the order numbers in the range K to L inclusively.
Array21. An array of N real numbers and two integers K and L (1 ≤ K ≤ L ≤ N) are given. Find the average of array elements with the order numbers in the range K to L inclusively.
Array22. An array of N real numbers and two integers K and L (1 < K ≤ L ≤ N) are given. Find the sum of all array elements except ones with the order numbers in the range K to L inclusively.
Array23. An array of N real numbers and two integers K and L (1 < K ≤ L ≤ N) are given. Find the average of all array elements except ones with the order numbers in the range K to L inclusively.
Array24. An array of N distinct integers is given. If the array elements represent an arithmetic sequence (see Array3) then output its common difference, otherwise output 0.
Array25. An array of N nonzero integers is given. If the array elements represent a geometric sequence with integer common ratio (see Array4) then output its common ratio, otherwise output 0.
Array26. An array of N integers is given. If odd and even numbers are alternated in the array then output 0, otherwise output the order number of the first element that breaks the above condition.
Array27. An array of N nonzero integers is given. If positive and negative numbers are alternated in the array then output 0, otherwise output the order number of the first element that breaks the above condition.
Array28. Given an array A of N real numbers, find the minimum among elements with even order numbers: A_{2}, A_{4}, A_{6}, … .
Array29. Given an array A of N real numbers, find the maximum among elements with odd order numbers: A_{1}, A_{3}, A_{5}, … .
Array30. An array of N real numbers is given. Find the order numbers of array elements that are greater than their right neighbor. Output these order numbers in ascending order and also output the amount of such elements.
Array31. An array of N real numbers is given. Find the order numbers of array elements that are greater than their left neighbor. Output these order numbers in descending order and also output the amount of such elements.
Array32°. Given an array of N real numbers, find the order number of its first local minimum (an array element is called the local minimum if it is smaller than its neighbors).
Array33. Given an array of N real numbers, find the order number of its last local maximum (an array element is called the local maximum if it is greater than its neighbors).
Array34. Given an array of N real numbers, find the maximum among its local minimums (see the local minimum definition in Array32).
Array35. Given an array of N real numbers, find the minimum among its local maximums (see the local maximum definition in Array33).
Array36. Given an array of N real numbers, find the maximum among array elements that are neither local minimum nor local maximum (see the definitions of local minimum and local maximum in Array32 and Array33 respectively). If the array does not contain such elements then output 0 (as a real number).
Array37. Given an array of N real numbers, find the amount of its parts of ascending (that is, parts that contain elements whose values are in ascending order).
Array38. Given an array of N real numbers, find the amount of its parts of descending (that is, parts that contain elements whose values are in descending order).
Array39. Given an array of N real numbers, find the amount of its parts of monotonicity (that is, parts that contain elements whose values are in ascending or in descending order).
Array40. A real number R and an array A of N real numbers are given. Find the array element that is the nearest to the number R (i. e., an element A_{K} such that the value A_{K} − R is minimal).
Array41. Given an array of N real numbers, find two adjacent elements with the maximal sum of values and output these elements in ascending order of its indices.
Array42. A real number R and an array of N real numbers are given. Find two adjacent elements whose sum of values is the nearest to the number R and output these elements in ascending order of its indices (see the definition of two nearest numbers in Array40).
Array43. Given an array of N integers whose values are in ascending or in descending order, find the amount of its elements with distinct values.
Array44. An array of N integers is given, the array contains two elements with equal values. Find these elements and output their order numbers in ascending order.
Array45. Given an array of N real numbers, find two nearest array elements (i. e., two different elements A_{K} and A_{L} such that the value A_{K} − A_{L} is minimal) and output their order numbers in ascending order.
Array46. A real number R and an array of N real numbers are given. Find two different elements such that the sum of their values is the nearest to the number R, and output these elements in ascending order of indices (see the definition of two nearest numbers in Array40).
Array47°. Given an array of N integers, find the amount of its elements with distinct values.
Array48. Given an array of N integers, find the maximal amount of its elements with equal values.
Array49. An array of N integers is given. If the array is a permutation (i. e., if the array contains all integers in the range 1 to N) then output 0, otherwise output the order number of the first inadmissible element.
Array50. An array A of N integers is given, the array is a permutation (see the permutation definition in Array49). Find the amount of inversions in this permutation (i. e., the amount of pairs of elements A_{I} and A_{J} such that I < J and A_{I} > A_{J}).
Work with several onedimensional arrays
Array51. Two arrays A and B of N real numbers are given. Exchange the contents of the given arrays and output elements of the changed array A and then output elements of the changed array B.
Array52. Given an array A of N real numbers, create a new array B of the same size with elements defined as: B_{K}  =  2·A_{K},  if A_{K} < 5,    A_{K}/2  otherwise. 
Array53. Two arrays A and B of N real numbers are given. Create a new array C of the same size; each element C_{K} must be equal to the largest of elements of A and B with the same index K.
Array54°. An array A of N integers is given. Write elements of A whose values are even numbers to a new array B (in the same order) and output the size of array B and all its elements.
Array55. An array A of N (≤ 15) integers is given. Write elements of A with odd order numbers (1, 3, …) to a new array B and output the size of array B and all its elements. Do not use conditional statements.
Array56. An array A of N (≤ 15) integers is given. Write elements of A with order numbers that are multiples of 3 (3, 6, …) to a new array B and output the size of array B and all its elements. Do not use conditional statements.
Array57. An array A of N integers is given. Write elements of A with even order numbers to a new array B and then write elements of A with odd order numbers to the same array B, so the array B will contain the following elements: A_{2}, A_{4}, A_{6}, …, A_{1}, A_{3}, A_{5}, … . Do not use conditional statements.
Array58. An array A of N real numbers is given. Create a new array B of the same size; each array element B_{K} must be equal to the sum of elements of A with the order numbers in the range 1 to K.
Array59. An array A of N real numbers is given. Create a new array B of the same size; each array element B_{K} must be equal to the average of elements of A with the order numbers in the range 1 to K.
Array60. An array A of N real numbers is given. Create a new array B of the same size; each array element B_{K} must be equal to the sum of elements of A with the order numbers in the range K to N.
Array61. An array A of N real numbers is given. Create a new array B of the same size; each array element B_{K} must be equal to the average of elements of A with the order numbers in the range K to N.
Array62. Given an array A of N real numbers, create two new arrays B and C and write all positive elements of A to the array B and all negative elements of A to the array C (in the same order). Output the size of the array B and all its elements and then output the size of the array C and all its elements.
Array63°. Two arrays A and B of 5 real numbers are given. Values of elements of each array are in ascending order. Write all elements of A and B to a new array C (of size 10) so that values of all elements of C were in ascending order.
Array64. Three arrays A, B, C of N_{A}, N_{B}, N_{C} integers are given. Values of elements of each array are in descending order. Write all elements of A, B, C to a new array D (of size N_{A} + N_{B} + N_{C}) so that values of all elements of D were in descending order.
Onedimensional arrays: changing
Array65. An array A of N real numbers and an integer K (1 ≤ K ≤ N) are given. Increase the value of each element of A by the initial value of A_{K}.
Array66. An array of N integers is given. Increase all even numbers contained in the array by the initial value of the first even number in the array. If the array does not contain even numbers then do not change it.
Array67. An array of N integers is given. Increase all odd numbers contained in the array by the initial value of the last odd number in the array. If the array does not contain odd numbers then do not change it.
Array68. Given an array of N real numbers, exchange values of its minimal and maximal element.
Array69. Given an array of N real numbers (N is an even number), exchange values of its first and second element, its third and fourth element, and so on.
Array70. Given an array of N real numbers (N is an even number), exchange values of the first half and the second half of its elements.
Array71°. Given an array of N real numbers, change the order of its elements to inverse one.
Array72. An array A of N real numbers and two integers K and L (1 ≤ K < L ≤ N) are given. Change the order of the array elements between A_{K} and A_{L} (including these elements) to inverse one.
Array73. An array A of N real numbers and two integers K and L (1 ≤ K < L ≤ N) are given. Change the order of the array elements between A_{K} and A_{L} (not including these elements) to inverse one.
Array74. An array of N real numbers is given. Assign zero value to the array elements between the minimal element and the maximal element (not including these elements).
Array75. An array of N real numbers is given. Change the order of the array elements between the minimal element and the maximal element (including these elements) to inverse one.
Array76. Given an array of N real numbers, assign zero value to all its local maximums (an array element is called the local maximum if it is greater than its neighbors).
Array77. Given an array of N real numbers, replace each local minimum with its square (an array element is called the local minimum if it is smaller than its neighbors).
Array78. Given an array of N real numbers, replace each array element with the average of this element and its neighbors.
Array79°. Given an array of N real numbers, perform the right shift of array elements on one position by assigning initial values of A_{1}, A_{2}, …, A_{N−1} to elements A_{2}, A_{3}, …, A_{N} respectively (an initial value of the last element will be lost). Assign zero value to the first element of the changed array.
Array80. Given an array of N real numbers, perform the left shift of array elements on one position by assigning initial values of A_{N}, A_{N−1}, …, A_{2} to elements A_{N−1}, A_{N−2}, …, A_{1} respectively (an initial value of the first element will be lost). Assign zero value to the last element of the changed array.
Array81. Given an array of N real numbers and an integer K (1 ≤ K < N), perform the right shift of array elements on K positions by assigning initial values of A_{1}, A_{2}, …, A_{N−K} to elements A_{K+1}, A_{K+2}, …, A_{N} respectively (an initial value of the last K elements will be lost). Assign zero value to the first K elements of the changed array.
Array82. Given an array of N real numbers and an integer K (1 ≤ K < N), perform the left shift of array elements on K positions by assigning initial values of A_{N}, A_{N−1}, …, A_{K+1} to elements A_{N−K}, A_{N−K−1}, …, A_{1} respectively (an initial value of the first K elements will be lost). Assign zero value to the last K elements of the changed array.
Array83. Given an array of N real numbers, perform the right cyclic shift of array elements on one position by assigning initial values of A_{1}, A_{2}, …, A_{N−1}, A_{N} to elements A_{2}, A_{3}, …, A_{N}, A_{1} respectively.
Array84. Given an array of N real numbers, perform the left cyclic shift of array elements on one position by assigning initial values of A_{N}, A_{N−1}, …, A_{2}, A_{1} to elements A_{N−1}, A_{N−2}, …, A_{1}, A_{N} respectively.
Array85. Given an array of N real numbers and an integer K (1 ≤ K ≤ 4, K < N), perform the right cyclic shift of array elements on K positions by assigning initial values of A_{1}, A_{2}, …, A_{N} to elements A_{K+1}, A_{K+2}, …, A_{K} respectively. An additional array of 4 elements may be used for performing the required shift.
Array86. Given an array of N real numbers and an integer K (1 ≤ K ≤ 4, K < N), perform the left cyclic shift of array elements on K positions by assigning initial values of A_{N}, A_{N−1}, …, A_{1} to elements A_{N−K}, A_{N−K−1}, …, A_{N−K+1} respectively. An additional array of 4 elements may be used for performing the required shift.
Array87. An array of N real numbers is given. The values of all array elements, except the first one, are in ascending order. Arrange all array elements in ascending order by moving the first element to a new position.
Array88. An array of N real numbers is given. The values of all array elements, except the last one, are in ascending order. Arrange all array elements in ascending order by moving the last element to a new position.
Array89°. An array of N real numbers is given. The values of all array elements, except one element, are in descending order. Arrange all array elements in descending order by moving the element, that violates ordering, to a new position.
Array90. An array of N real numbers and an integer K (1 ≤ K ≤ N) are given. Remove an element with the order number K from the array.
Array91. An array of N real numbers and two integers K and L (1 ≤ K < L ≤ N) are given. Remove elements with the order numbers in the range K to L inclusively from the array and output the size of the changed array and all its elements.
Array92°. Given an array of N integers, remove all odd numbers from the array and output the size of the changed array and all its elements.
Array93. Given an array of N (> 2) integers, remove all elements with even order numbers (2, 4, …) from the array. Do not use conditional statements.
Array94. Given an array of N (> 2) integers, remove all elements with odd order numbers (1, 3, …) from the array. Do not use conditional statements.
Array95. Given an array of N integers, remove all successive equal elements (except for their first occurrence) from the array.
Array96. Given an array of N integers, remove all equal elements (except for their first occurrence) from the array.
Array97. Given an array of N integers, remove all equal elements (except for their last occurrence) from the array.
Array98. Given an array of N integers, remove all elements whose values appear less than three times in the array. Output the size of the changed array and all its elements.
Array99. Given an array of N integers, remove all elements whose values appear more than twice in the array. Output the size of the changed array and all its elements.
Array100. Given an array of N integers, remove all elements whose values appear exactly twice in the array. Output the size of the changed array and all its elements.
Array101. An array of N real numbers and an integer K (1 ≤ K ≤ N) are given. Insert a new element with zero value before an element with the order number K.
Array102. An array of N real numbers and an integer K (1 ≤ K ≤ N) are given. Insert a new element with zero value after an element with the order number K.
Array103. An array of N real numbers is given. Insert new elements with zero value before an element with the minimal value and after an element with the maximal value.
Array104. An array of N real numbers and two integers K and M (1 ≤ K ≤ N, 1 ≤ M ≤ 10) are given. Insert M new elements with zero value before an element with the order number K.
Array105. An array of N real numbers and two integers K and M (1 ≤ K ≤ N, 1 ≤ M ≤ 10) are given. Insert M new elements with zero value after an element with the order number K.
Array106. Given an array of N real numbers, double occurrences of elements with even order numbers (2, 4, …). Do not use conditional statements in loops.
Array107. Given an array of N real numbers, triple occurrences of elements with odd order numbers (1, 3, …). Do not use conditional statements in loops.
Array108°. Given an array of N real numbers, insert an element with zero value before each element with positive value.
Array109. Given an array of N real numbers, insert an element with zero value after each element with negative value.
Array110. Given an array of N integers, double occurrences of all elements whose values are even numbers.
Array111. Given an array of N integers, triple occurrences of all elements whose values are odd numbers.
Array112°. An array A of N (≤ 6) real numbers is given. Sort the array in ascending order by using the exchange sort method (the bubble sorting): compare each pair of two adjacent elements (A_{1} and A_{2}, A_{2} and A_{3}, and so on) and exchange their values in case the left element is greater than the right one; repeat N − 1 times such array pass. Output all array elements after each pass for checking results. Note that the amount of analyzed pairs of the array elements can be reduced by 1 after each pass.
Array113. An array A of N (≤ 6) real numbers is given. Sort the array in ascending order by using the selection sort method: find the greatest element in the array and exchange the values of the greatest element and the last element (with the order number N); repeat N − 1 times this process, reducing the amount of analyzed elements by 1 after each array pass. Output all array elements after each pass for checking results.
Array114. An array A of N (≤ 6) real numbers is given. Sort the array in ascending order by using the insertion sort method: compare an element A_{2} with the first element A_{1} and exchange their values, if necessary, so that these elements were in ascending order; then move an element A_{3} to the left (sorted) part of the array, so that three elements were in ascending order; repeat this process for other array elements. Output all array elements after processing of each element (from A_{2} to A_{N}). Note that it is convenient to assign the array element being processed to an additional array element A_{0} (the barrier element).
Array115. An array A of N real numbers is given. Without changing the array A, output the order numbers that correspond to array elements in ascending order of their values. For solving the task create an additional index array I, which contains order numbers in the range 1 to N, and use the bubble sorting (see Array112) as follows: compare elements of array A (with the order numbers I_{1} and I_{2}, I_{2} and I_{3}, and so on) and exchange, if necessary, values of corresponding elements of index array I. After repeating N − 1 times of such array pass the required sequence of order numbers will be contained in the array I.
Onedimensional arrays: series of equal numbers
Array116°. An array A of N integers is given. A group of successive array elements with equal values is called a series of equal numbers, the amount of its elements is called a length of series (a length of series may be equal to 1), the value of its elements is called a value of series. Create and output two new integervalued arrays B and C containing respectively lengths and values of all series of equal numbers of the array A.
Array117. Given an array of N integers, insert an element with zero value before each series of equal numbers of the array (see the series definition in Array116).
Array118. Given an array of N integers, insert an element with zero value after each series of equal numbers of the array (see the series definition in Array116).
Array119. Given an array of N integers, increase each series of equal numbers of the array by one element (see the series definition in Array116).
Array120. An array of N integers is given. The array contains at least one series of two or more equal numbers. Decrease each series of equal numbers of the array by one element (see the series definition in Array116).
Array121. An integer K (> 0) and an array of N integers are given. Double the length of the Kth series of equal numbers of the array (see the series definition in Array116). If the array contains less than K series then do not change it.
Array122. An integer K (> 1) and an array of N integers are given. Remove the Kth series of equal numbers from the array (see the series definition in Array116). If the array contains less than K series then do not change it.
Array123. An integer K (> 1) and an array of N integers are given. Exchange the first and the Kth series of equal numbers of the array (see the series definition in Array116). If the array contains less than K series then do not change it.
Array124. An integer K (> 1) and an array of N integers are given. Exchange the last and the Kth series of equal numbers of the array (see the series definition in Array116). If the array contains less than K series then do not change it.
Array125. An integer L (> 1) and an array of N integers are given. Replace each series, whose length is less than L, by one element with zero value (see the series definition in Array116).
Array126. An integer L (> 0) and an array of N integers are given. Replace each series, whose length is equal to L, by one element with zero value (see the series definition in Array116).
Array127. An integer L (> 0) and an array of N integers are given. Replace each series, whose length is greater than L, by one element with zero value (see the series definition in Array116).
Array128. Given an array of N integers, increase its first series of the maximal length by one element (see the series definition in Array116).
Array129. Given an array of N integers, increase its last series of the maximal length by one element (see the series definition in Array116).
Array130. Given an array of N integers, increase all its series of the maximal length by one element (see the series definition in Array116).
Onedimensional arrays: sets of points
Array131. A set A of N points in the coordinate plane and a point B are given (all points are determined by their coordinates x, y). Find the point of A that is the nearest to the point B. The distance R between two points with the coordinates (x_{1}, y_{1}) and (x_{2}, y_{2}) may be found by formula: R = ((x_{2} − x_{1})^{2} + (y_{2} − y_{1})^{2})^{1/2}.
Array132. A set A of N points in the coordinate plane is given (points are determined by their coordinates x, y). Find the point of A that lies in the second coordinate quarter and is the farthest from the origin. If the set A does not contain such points then output the origin (0, 0).
Array133. A set A of N points in the coordinate plane is given (points are determined by their coordinates x, y). Find the point of A that lies in the first or the third coordinate quarter and is the nearest to the origin. If the set A does not contain such points then output the origin (0, 0).
Array134°. A set A of N points in the coordinate plane is given (points are determined by their coordinates x, y). Find two points of A with the maximal distance between them and output these points (in ascending order of their indices in the set A) and the value of the distance.
Array135. Two sets A and B of N_{1} and N_{2} points respectively are given (points are determined by their coordinates x, y). Find the point of A and the point of B with the minimal distance between them. Output the value of the distance and then the point of A and the point of B.
Array136. A set A of N points in the coordinate plane is given (N > 2, points are determined by their coordinates x, y). Find the point of A such that the sum of distances between this point and other points of A is minimal and output this point and the corresponding sum.
Array137. A set A of N points in the coordinate plane is given (N > 2, points are determined by their coordinates x, y). Find the maximal perimeter of a triangle with vertices belonging to A. Output this perimeter and the corresponding vertices (in ascending order of their indices in the set A).
Array138. A set A of N points in the coordinate plane is given (N > 2, points are determined by their coordinates x, y). Find the minimal perimeter of a triangle with vertices belonging to A. Output this perimeter and the corresponding vertices (in ascending order of their indices in the set A).
Array139. A set A of N points with integervalued coordinates x, y is given. The order in the plane is defined as follows: (x_{1}, y_{1}) < (x_{2}, y_{2}), if either x_{1} < x_{2} or x_{1} = x_{2} and y_{1} < y_{2}. Using this order definition, rearrange points of A in ascending order.
Array140. A set A of N points with integervalued coordinates x, y is given. The order in the plane is defined as follows: (x_{1}, y_{1}) < (x_{2}, y_{2}), if either x_{1} + y_{1} < x_{2} + y_{2} or x_{1} + y_{1} = x_{2} + y_{2} and x_{1} < x_{2}. Using this order definition, rearrange points of A in descending order.
