From a3ef1d98058247f1d81d32f0257c98986b01bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=9A=D0=B0=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= Date: Thu, 6 Nov 2025 16:37:25 +0300 Subject: [PATCH 1/5] Update Blue.cs --- Lab4/Blue.cs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/Lab4/Blue.cs b/Lab4/Blue.cs index c0b1797..aa98c27 100644 --- a/Lab4/Blue.cs +++ b/Lab4/Blue.cs @@ -9,6 +9,49 @@ public void Task1(int[] array) // code here + int negativePosition = 0; + + for (int i = 0; i < array.Length; i++) + { + if (array[i] < 0) + { + negativePosition = i; + break + } + } + + int maxValue = 0; + for (int i = 0; i < array.Length; i++) + { + if (maxValue < Math.Max(array[i], array[i+1]) + { + maxValue = Math.Max(array[i], array[i+1]); + } + } + + int maxPosition = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] == maxValue) + { + maxPosition = i; + break; + } + } + + int sum = 0; + + if (maxPosition != array.Length - 1) + { + for (int i = maxPosition + 1; i < array.Length; i++) + { + sum += array[i]; + } + } + + array[maxPosition] = sum; + + // end } @@ -122,4 +165,5 @@ public int[] Task12(int[] magazine) return indexes; } } -} \ No newline at end of file + +} From bc54efffd1f52e19176da2d4e9f0b9a14d892c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=9A=D0=B0=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= Date: Thu, 6 Nov 2025 21:21:14 +0300 Subject: [PATCH 2/5] Update Blue.cs --- Lab4/Blue.cs | 220 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 205 insertions(+), 15 deletions(-) diff --git a/Lab4/Blue.cs b/Lab4/Blue.cs index aa98c27..30acbfc 100644 --- a/Lab4/Blue.cs +++ b/Lab4/Blue.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; + using System.Runtime.InteropServices; namespace Lab4 { @@ -8,7 +8,18 @@ public void Task1(int[] array) { // code here +// PROBLEM ONE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Первый отрицательный элемент массива заменить суммой элементов, расположенных после максимального элемента массива. + // Если максимальный элемент последний, сумма после него считается равной 0. + + // The first negative element is replaced by the sum of the elements that follow the highest positive number + // If there is no element after the highest positive number, the sum will be treated as 0 + + //---------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // We begin by finding out the position of the first negative number + int negativePosition = 0; for (int i = 0; i < array.Length; i++) @@ -16,10 +27,14 @@ public void Task1(int[] array) if (array[i] < 0) { negativePosition = i; - break + break; } } + // Now that we have found it, we need to find the highest positive number, we begin by finding it's value + // We scour through the array and make successive comparasions, this brings up a problem however, as it seems we cannot do a holistic comparison + // That's why we define a variable where we will store the value and ensure that it's constantly compared through the loops + int maxValue = 0; for (int i = 0; i < array.Length; i++) { @@ -29,6 +44,8 @@ public void Task1(int[] array) } } + // Now that we know the maximum value, we need to find it's position + int maxPosition = 0; for (int i = 0; i < array.Length; i++) { @@ -40,7 +57,6 @@ public void Task1(int[] array) } int sum = 0; - if (maxPosition != array.Length - 1) { for (int i = maxPosition + 1; i < array.Length; i++) @@ -49,9 +65,9 @@ public void Task1(int[] array) } } - array[maxPosition] = sum; - + array [maxPosition] = sum; +//--------------------------------------------------------------------------------------------------------------------------------------------- // end } @@ -60,7 +76,65 @@ public int[] Task2(int[] array, int P) int[] answer = null; // code here +// PROBLEM TWO----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array и число P. Вставить заданный элемент P после последнего положительного элемента массива и вернуть как новый массив. + // Если в массиве нет положительных элементов, вернуть копию исходного массива. + + // Insert the element P after the last positive element and return it as a new array. + // If the array doesn't have positive elements, return a copy of the array + //-------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // We begin by searching for the last positive element, since we want the last one, we begin from the end of the array + int positivePosition = 0; + for (int i = array.Length - 1; i >= 0; i--) + { + if (array[i] > 0) + { + positivePosition = i; + break; + } + } + + // If our array did not had any positive elements, then it would not have changed the value of our variable + // Therefore we set up a conditional, declare our answer array and use a for loop to copy the elements (we need to do this manually) + if (positivePosition == 0) + { + int[] answer = new int[array.Length]; + for (int i = 0; i < array.Length; i++) + { + answer[i] = array[i]; + } + return answer; + } + + // Now we create our new array, which is the same size as the original one but bigger by one (we added P) + // We make a new variable for the size + int n = array.Length + 1; + + // Here is the array + int[] answer = new int[n]; + + // Now we need to populate it + // We are going to do so in three steps + // PART ONE: We are going to make a for loop, that runs until we reach the highest number (inclusive), we will just copy the elements + // PART TWO: We are going to assign "P" to the next position + // PART THREE: We are going to make a new loop again, but this time, we will begin onwards from P (exclusive) and we will copy the elements + // BUT we need to take into account that the original array is smaller, so we are going to copy the elements "i-1" (adding P created an offset) + for (int i = 0; i <= positivePosition; i++) + { + answer[i] = array[i]; + } + + answer[positivePosition + 1] = P; + + for (int i = positivePosition + 2; i < answer.Length; i++) + { + answer[i] = array[i - 1]; + } + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return answer; @@ -70,7 +144,18 @@ public int[] Task3(int[] array) int[] answer = null; // code here - +// PROBLEM THREE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Удалить минимальный среди положительных элементов массива. + // Если в массиве нет положительных элементов, вернуть копию исходного массива. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return answer; @@ -79,7 +164,18 @@ public void Task4(double[] array) { // code here - +// PROBLEM FOUR----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Найти среднее значение элементов массива. + // Преобразовать элементы исходного массива, вычитая из каждого элемента полученное значение. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end } @@ -88,7 +184,18 @@ public int Task5(int[] A, int[] B) int sum = 0; // code here - +// PROBLEM FIVE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передаются одномерные массивы A и B. Вычислить скалярное произведение массивов A и B. + // Скалярным произведением называется сумма попарных произведений соответствующих элементов массивов. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return sum; @@ -98,7 +205,16 @@ public int[] Task6(int[] array) int[] indexes = null; // code here - +// PROBLEM SIX----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Индексы элементов массива, меньших среднего, поместить в новый массив. + + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return indexes; @@ -108,7 +224,18 @@ public int Task7(int[] array) int count = 0; // code here - +// PROBLEM SEVEN----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Определить длину самой большой непрерывнойупорядоченной (по возрастанию или по убыванию) последовательности. + // Последовательность считается непрерывной, если её элементы равны или их попарная разность одного знака. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return count; @@ -118,7 +245,18 @@ public int[] Task8(int[] array) int[] answer = null; // code here - +// PROBLEM EIGHT----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Продублировать все элементы с сохранением порядка следования. + // Например, передается array = {3, 8, ...}, получить array = {3, 3, 8, 8, ...}. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return answer; @@ -128,7 +266,18 @@ public double[] Task9(int[] array) double[] normalized = null; // code here - +// PROBLEM NINE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array. Нормировать значения массива, чтобы его элементы принадлежали отрезку [0, 1]. + // Если все элементы массива равны, вернуть null. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return normalized; @@ -138,7 +287,18 @@ public int Task10(int[] array, int P) int index = 0; // code here - +// PROBLEM TEN----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передается одномерный массив array и число P. Отсортировать массив по возрастанию и найти индекс числа P бинарным поиском в отсортированном массиве. + // Вернуть -1, если число не найдено. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return index; @@ -148,7 +308,19 @@ public int[] Task11(int a, int b, int c) int[] array = null; // code here - +// PROBLEM ELEVEN----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // В метод передаются целые числа a, b, c. + // Сформировать массив из элементов, начинающийся с элемента a, увеличивая значение каждого последующего элемента на b до тех пор, пока элемент не превысит значение c. + // Число b должно быть положительным. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return array; @@ -159,7 +331,24 @@ public int[] Task12(int[] magazine) int[] indexes = null; // code here - +// PROBLEM TWELVE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START + // Группа археологов исследуют древнюю египетскую гробницу. + // Внутри они обнаружили несколько запечатанных комнат, в каждой из которых, по слухам, хранятся золотые слитки фараона. + // Однако не все комнаты сохранились нетронутыми — некоторые были разграблены еще в древности. + // Записи о количестве золотых слитков в каждой пронумерованной комнате были записаны в журнал magazine. + // Нулевые значения означают, что комната пуста. У археологов есть время посетить только 3 соседние комнаты и забрать оттуда золото. + // Помогите им выбрать, какие 3 комнаты нужно посетить, чтобы забрать как можно больше золотых слитков. + // Если комнат меньше 3-х, то посетить все, что есть. + // Ответ представить в виде массива индексов комнат. + + // + // + + + + + +//--------------------------------------------------------------------------------------------------------------------------------------------- // end return indexes; @@ -167,3 +356,4 @@ public int[] Task12(int[] magazine) } } + From 88ee117673af1ed076f91672b4bf6e82c04dee2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=9A=D0=B0=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= Date: Thu, 6 Nov 2025 22:21:01 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9A=D0=B0=D0=B1=D1=80=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=20=D0=A1=D0=B0=D1=80=D0=BC=D1=8C=D0=B5=D0=BD=D1=82=D0=BE=20?= =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=A5=D0=B0=D0=B2=D1=8C=D0=B5?= =?UTF-8?q?=D1=80=20=D0=91=D0=98=D0=92=D0=A2-25-11=20Blue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab4/Blue.cs | 107 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/Lab4/Blue.cs b/Lab4/Blue.cs index 30acbfc..64b2a65 100644 --- a/Lab4/Blue.cs +++ b/Lab4/Blue.cs @@ -148,12 +148,43 @@ public int[] Task3(int[] array) // В метод передается одномерный массив array. Удалить минимальный среди положительных элементов массива. // Если в массиве нет положительных элементов, вернуть копию исходного массива. - // - // - + // Delete the lowest positive number in the array + // If the array doesn't have positive numbers, return a copy of the array - - + int minValue = 99999; + int minPosition = 0; + + for (int i = 0; i < array.Length; i++) + { + if (minValue > 0 && minValue < Math.Min(array[i], array[i+1]) ) + { + minValue = Math.Min(array[i], array[i+1]); + minPosition = i; + } + } + + if (minValue == 99999) + { + int[] answer = new int[array.Length]; + for (int i = 0; i < array.Length; i++) + { + answer[i] = array[i]; + } + return answer; + } + + int n2 = array.Length - 1; + int[] answer = new int[n2]; + + for (int i = 0; i < minPosition; i++) + { + answer[i] = array[i]; + } + + for (int i = minPosition + 1; i < n2; i++) + { + answer[i] = array[i + 1]; + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -168,12 +199,20 @@ public void Task4(double[] array) // В метод передается одномерный массив array. Найти среднее значение элементов массива. // Преобразовать элементы исходного массива, вычитая из каждого элемента полученное значение. - // - // - - - - + // Find the average of the elements of the array + // Substract the average from the value of each element + + double average = 0; + for (int i = 0; i < array.Length; i++) + { + average += array[i]; + } + average /= array.Length; + + for (int i = 0; i < array.Length; i++) + { + array[i] -= average; + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -188,12 +227,13 @@ public int Task5(int[] A, int[] B) // В метод передаются одномерные массивы A и B. Вычислить скалярное произведение массивов A и B. // Скалярным произведением называется сумма попарных произведений соответствующих элементов массивов. - // - // - - - - + // We are given 2 arrays: A and B. Determine the scalar product of A and B. + // A Scalar product is defined as the sum of the products of each element. + + for (int i = 0; i < A.Length; i++) + { + sum += A[i] * B[i]; + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -208,11 +248,35 @@ public int[] Task6(int[] array) // PROBLEM SIX----------------------------------------------------------------------------------------------------------------------------------------------------------------------------START // В метод передается одномерный массив array. Индексы элементов массива, меньших среднего, поместить в новый массив. - // + // The indexes of the elements of the array, which are lesser than the average, must be put in a new array - - - + double averages = 0; + for (int i = 0; i < array.Length; i++) + { + averages += array[i]; + } + averages /= array.Length; + + int arraySize = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] < averages) + { + arraySize++; + } + } + + int[] indexes = new int[arraySize]; + + int j = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] < averages) + { + answer[j] = i; + j++; + } + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -357,3 +421,4 @@ public int[] Task12(int[] magazine) } + From 49377afafd18aaa7c8e7296df1b4f7e049fc74b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=9A=D0=B0=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= Date: Thu, 6 Nov 2025 23:42:49 +0300 Subject: [PATCH 4/5] Update Blue.cs --- Lab4/Blue.cs | 89 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 21 deletions(-) diff --git a/Lab4/Blue.cs b/Lab4/Blue.cs index 64b2a65..6a2d3c1 100644 --- a/Lab4/Blue.cs +++ b/Lab4/Blue.cs @@ -38,7 +38,7 @@ public void Task1(int[] array) int maxValue = 0; for (int i = 0; i < array.Length; i++) { - if (maxValue < Math.Max(array[i], array[i+1]) + if (maxValue < Math.Max(array[i], array[i+1]) ) { maxValue = Math.Max(array[i], array[i+1]); } @@ -273,7 +273,7 @@ public int[] Task6(int[] array) { if (array[i] < averages) { - answer[j] = i; + indexes[j] = i; j++; } } @@ -292,12 +292,16 @@ public int Task7(int[] array) // В метод передается одномерный массив array. Определить длину самой большой непрерывнойупорядоченной (по возрастанию или по убыванию) последовательности. // Последовательность считается непрерывной, если её элементы равны или их попарная разность одного знака. - // - // + // Determine the length of the longest continuous ordered sequence (either increasing or decreasing). + // A sequence is considered continuous if its elements are equal, or if the pairwise differences betweem consecutive elements have the same sign - - - + for (int i = 0; i < array.Length; i++) + { + if (array[i] >= array[i+1] && Math.Sign(array[i]) == Math.Sign(array[i+1]) ) + { + count++; + } + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -313,12 +317,19 @@ public int[] Task8(int[] array) // В метод передается одномерный массив array. Продублировать все элементы с сохранением порядка следования. // Например, передается array = {3, 8, ...}, получить array = {3, 3, 8, 8, ...}. - // - // - - - - + // Duplicate all array elements preserving their order + // Ex. array = {3, 8, ...}, becomes array = {3, 3, 8, 8, ...} + + int dupeSize = 2 * array.Length; + int[] answer = new int[dupeSize]; + + int k = 0; + for (int i = 0; i < array.Length; i++) + { + answer[k] = array[i]; + answer[k+1] = array[i]; + k += 2; + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -334,12 +345,44 @@ public double[] Task9(int[] array) // В метод передается одномерный массив array. Нормировать значения массива, чтобы его элементы принадлежали отрезку [0, 1]. // Если все элементы массива равны, вернуть null. - // - // - + // Normalize the elements of an array so that each of them belong to the interval [0, 1]. + // If all elements are the same, return null + + if (array.Length <= 1 || array == null) + { + return normalized; + } + + for (int i = 0; i < array.Length; i++) + { + if (array[i] == array[i+1]) + { + return normalized; + } + } + + double[] normalized = new double[array.Length]; - - + int xMin = 0; + int xMax = 0; + + for (int i = 0; i < array.Length; i++) + { + if (xMax < Math.Max(array[i], array[i+1]) ) + { + xMax = Math.Max(array[i], array[i+1]); + } + + if (xMin < Math.Min(array[i], array[i+1]) ) + { + xMin = Math.Min(array[i], array[i+1]); + } + } + + for (int i = 0; i < array.Length; i++) + { + normalized[i] = (array[i] - xMin) / (xMax - xMin); + } //--------------------------------------------------------------------------------------------------------------------------------------------- // end @@ -355,10 +398,13 @@ public int Task10(int[] array, int P) // В метод передается одномерный массив array и число P. Отсортировать массив по возрастанию и найти индекс числа P бинарным поиском в отсортированном массиве. // Вернуть -1, если число не найдено. - // - // - + // Sort the array in ascending order and find the index of the number P using binary search in the sorted array + // Return -1 if the number is not found + + for (int i = 0; i < array.Length; i++) + { + @@ -422,3 +468,4 @@ public int[] Task12(int[] magazine) } + From 26053306a1d60615e0de53fe32bb27867e5dc60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D0=BD=D1=80=D0=B8=20=D0=9A=D0=B0=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= Date: Fri, 7 Nov 2025 00:45:34 +0300 Subject: [PATCH 5/5] Update Blue.cs --- Lab4/Blue.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Lab4/Blue.cs b/Lab4/Blue.cs index 6a2d3c1..314bea3 100644 --- a/Lab4/Blue.cs +++ b/Lab4/Blue.cs @@ -401,10 +401,40 @@ public int Task10(int[] array, int P) // Sort the array in ascending order and find the index of the number P using binary search in the sorted array // Return -1 if the number is not found + + + int minNumber = 99999; + int maxNumber = -99999; + int minIndex = 0; + int maxIndex = 0; for (int i = 0; i < array.Length; i++) { + if ( minNumber > Math.Min(array[i], array[i+1]) ) + { + minNumber = Math.Min(array[i], array[i+1]); + minIndex = i; + } + if ( maxNumber < Math.Max(array[i], array[i+1]) ) + { + maxNumber = Math.Max(array[i], array[i+1]); + maxIndex = i; + } + } + + + for (int i = 0; i < array.Length; i++) + { + //do + //{ + //array[i] = Math.Min(array[i], array[i+1]); + //array[i+1] = Math.Max(array[i], array[i+1]); + //} + //while (array[minIndex] != array[0] || array[maxIndex] != array[array.Length - 1]); + } + + @@ -469,3 +499,4 @@ public int[] Task12(int[] magazine) +