From 32d54bd8dccf19cf7ca5a44501ed7fef80b57795 Mon Sep 17 00:00:00 2001 From: Mark <112826355+NemirovichMark@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:54:06 +0300 Subject: [PATCH 1/5] Add files via upload --- Lab5test/PurpleTest.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lab5test/PurpleTest.cs b/Lab5test/PurpleTest.cs index de6f180..0739cca 100644 --- a/Lab5test/PurpleTest.cs +++ b/Lab5test/PurpleTest.cs @@ -246,15 +246,15 @@ public void Test04() }, new int[,] { {1, 2, 4, 6}, - {5, 0, 7, 11}, - {0, 4, 0, 6}, + {5, -6, 7, 11}, + {-1, 4, -5, 6}, {1, 4, 5, 6}, }, new int[,] { {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 0, 10, 11}, + {5, 6, 7, 8, -9, 10, 11}, {9, 10, -11, -12, -13, -14, -15}, - {0, 0, 15, 16, 17, 18, -19}, + {-13, -14, 15, 16, 17, 18, -19}, }, new int[,] { {1, 2, 3}, @@ -262,30 +262,30 @@ public void Test04() {0, -2, -3}, }, new int[,] { - {0, 0, 0, 0, 0, 6}, + {-9, -10, -11, -14, -15, 6}, }, new int[,] { {1, 2, 3, 4, -5, -6, -7}, {5, 11, -17, 11, -10, 6, 5}, - {0, 0, 0, 0, 0, 0, 1}, - {0, 0, 0, 0, 0, 0, -2}, + {-9, -10, -11, -14, -15, -16, 1}, + {-9, -10, -11, -14, -15, -6, -2}, {4, 4, 4, 4, 4, 6, 4}, }, new int[,] { {1, 2, 3, 4, -5, -6, -7}, {5, 11, -17, 11, -10, 6, 5}, - {0, 0, 0, 0, 0, 0, 1}, - {0, 0, 0, 0, 15, -6, -2}, + {-9, -10, -11, -14, -15, -16, 1}, + {-9, -10, -11, -14, 15, -6, -2}, {4, 4, 4, 4, 4, 6, 4}, {5, 11, -17, 11, -10, 6, -5}, - {1, 1, 1, 3, -4, 0, 0}, - {0, 0, 0, 0, 0, 0, 5}, + {1, 1, -2, 3, -4, 0, 0}, + {0, -2, -3, -4, -5, 0, 5}, }, new int[,] { {1, 2, 3, 4, -5}, {5, 11, -17, 11, 7}, {-9, -10, -11, -14, -15}, - {0, 0, 0, 0, -6}, + {-9, -10, -11, -14, -6}, {0, -2, -3, -4, -5}, } }; From c9b4eacfdd6bfcbb0fac4cd949adfb26776aebdf Mon Sep 17 00:00:00 2001 From: Mark <112826355+NemirovichMark@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:37:54 +0300 Subject: [PATCH 2/5] Add files via upload --- Lab5test/GreenTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lab5test/GreenTest.cs b/Lab5test/GreenTest.cs index 7bf55bd..393d258 100644 --- a/Lab5test/GreenTest.cs +++ b/Lab5test/GreenTest.cs @@ -245,10 +245,10 @@ public void Test04() {0, 2, 3, 4, 5, 6}, }, new int[,] { - {1, 2, 4, 5}, + {1, 2, 4, 1}, + {5, -6, 7, 4}, + {-1, 4, -5, 5}, {6, 11, 6, 6}, - {-1, 4, -5, 7}, - {1, 4, 5, 11}, }, new int[,] { {1, 2, 3, 4, 5, 6, 7}, From 22421c38be084a5586e05cac4e7f10a2add7243a Mon Sep 17 00:00:00 2001 From: Ezequiel Alejandro Zapata <157446504+Ezequiel-A-Zapata@users.noreply.github.com> Date: Mon, 1 Dec 2025 01:12:08 +0300 Subject: [PATCH 3/5] Update White.cs --- Lab5/White.cs | 369 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 348 insertions(+), 21 deletions(-) diff --git a/Lab5/White.cs b/Lab5/White.cs index 253bb13..6fce95f 100644 --- a/Lab5/White.cs +++ b/Lab5/White.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Runtime.InteropServices; namespace Lab5 @@ -10,7 +10,24 @@ public double Task1(int[,] matrix) double average = 0; // code here - + int count = 0; + int sum = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (matrix[i, j] > 0) + { + count++; + sum += matrix[i, j]; + } + } + } + if ( count > 0) + { + double promedio = (double)sum / count; + average = promedio; + } // end return average; @@ -18,8 +35,20 @@ public double Task1(int[,] matrix) public (int row, int col) Task2(int[,] matrix) { int row = 0, col = 0; - + int element = matrix[0,0]; // code here + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1) - 1; j++) + { + if (matrix[i,j] < element) + { + element = matrix[i, j]; + row = i; + col = j; + } + } + } // end @@ -29,7 +58,26 @@ public void Task3(int[,] matrix, int k) { // code here - + int maxNum = matrix[0, k]; + int maxRow = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (matrix[i, k] > maxNum) + { + maxNum = matrix[i, k]; + maxRow = i; + } + } + if (maxRow == 0) + { + return; + } + for (int j = 0; j < matrix.GetLength(1); j++) + { + int temp = matrix[0, j]; + matrix[0, j] = matrix[maxRow, j]; + matrix[maxRow, j] = temp; + } // end } @@ -38,17 +86,55 @@ public void Task3(int[,] matrix, int k) int[,] answer = null; // code here - + + if (matrix == null || matrix.GetLength(0) == 0) + return new int[0, matrix?.GetLength(1) ?? 0]; + + if (matrix.GetLength(0) == 1) + return new int[0, matrix.GetLength(1)]; // Matriz 0×m + int minRow = 0; + int minValue = matrix[0, 0]; + + for (int i = 1; i < matrix.GetLength(0); i++) + { + if (matrix[i, 0] < minValue) + { + minValue = matrix[i, 0]; + minRow = i; + } + } + // 2. Crear nueva matriz con una fila menos + int newRows = matrix.GetLength(0) - 1; + int cols = matrix.GetLength(1); + int[,] newMatrix = new int[newRows, cols]; + + // 3. Copiar todas las filas EXCEPTO la que vamos a eliminar + int newRowIndex = 0; + + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (i != minRow) // Saltar la fila a eliminar + { + for (int j = 0; j < cols; j++) + { + newMatrix[newRowIndex, j] = matrix[i, j]; + } + newRowIndex++; + } + } // end - return answer; + return newMatrix; } public int Task5(int[,] matrix) { int sum = 0; // code here - + for (int i = 0; i < matrix.GetLength(0); i++) + { + sum += matrix[i, i]; + } // end return sum; @@ -57,7 +143,59 @@ public void Task6(int[,] matrix) { // code here - + if (matrix == null) return; + + for (int i = 0; i < matrix.GetLength(0); i++) + { + int maxBeforeNegativeIndex = -1; + int maxBeforeNegativeValue = 0; // Ahora empezamos en 0 + bool foundFirstNegative = false; + bool foundPositive = false; // Nueva bandera + int lastNegativeIndex = -1; + + for (int j = 0; j < matrix.GetLength(1); j++) + { + int current = matrix[i, j]; + + // Buscar último negativo + if (current < 0) + { + lastNegativeIndex = j; + } + + // Buscar máximo antes del primer negativo + if (!foundFirstNegative) + { + if (current < 0) + { + foundFirstNegative = true; + } + else + { + // Si es el primer número positivo que encontramos + if (!foundPositive) + { + maxBeforeNegativeValue = current; + maxBeforeNegativeIndex = j; + foundPositive = true; + } + else if (current > maxBeforeNegativeValue) + { + maxBeforeNegativeValue = current; + maxBeforeNegativeIndex = j; + } + } + } + } + + // Intercambiar si encontramos ambos + if (maxBeforeNegativeIndex != -1 && lastNegativeIndex != -1) + { + int temp = matrix[i, maxBeforeNegativeIndex]; + matrix[i, maxBeforeNegativeIndex] = matrix[i, lastNegativeIndex]; + matrix[i, lastNegativeIndex] = temp; + } + } // end } @@ -66,52 +204,241 @@ public int[] Task7(int[,] matrix) int[] negatives = null; // code here - + if (matrix == null) + { + negatives = new int[0]; + return negatives; + } + + // Primero contar los elementos negativos + int count = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (matrix[i, j] < 0) + { + count++; + } + } + } + + // Si no hay negativos, retornar array vacío + if (count == 0) + { + negatives = new int[0]; + } + else + { + // Crear array del tamaño correcto y llenarlo + negatives = new int[count]; + int index = 0; + + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (matrix[i, j] < 0) + { + negatives[index] = matrix[i, j]; + index++; + } + } + } + } // end return negatives; } public void Task8(int[,] matrix) { - - // code here - - // end - + if (matrix == null) return; + + for (int i = 0; i < matrix.GetLength(0); i++) + { + // Si la fila tiene longitud 1, saltar a la siguiente + if (matrix.GetLength(1) <= 1) + continue; + + // Paso 1: Encontrar la posición del primer máximo + int maxIndex = 0; + int maxValue = matrix[i, 0]; + + for (int j = 1; j < matrix.GetLength(1); j++) + { + if (matrix[i, j] > maxValue) + { + maxValue = matrix[i, j]; + maxIndex = j; + } + } + + // Paso 2: Determinar qué elementos modificar + if (maxIndex == 0) // Máximo es el primero + { + // Solo aumentar el elemento después del máximo + matrix[i, maxIndex + 1] *= 2; + } + else if (maxIndex == matrix.GetLength(1) - 1) // Máximo es el último + { + // Solo aumentar el elemento antes del máximo + matrix[i, maxIndex - 1] *= 2; + } + else // Máximo está en el medio + { + // Comparar elementos antes y después del máximo + int before = matrix[i, maxIndex - 1]; + int after = matrix[i, maxIndex + 1]; + + if (before <= after) // Izquierdo si son iguales o menor + { + matrix[i, maxIndex - 1] *= 2; + } + else // Derecho es menor + { + matrix[i, maxIndex + 1] *= 2; + } + } + } } public void Task9(int[,] matrix) { + if (matrix == null) return; // code here - + for (int i = 0; i < matrix.GetLength(0); i++) + { + // Invertir la fila actual + for (int j = 0; j < matrix.GetLength(1) / 2; j++) + { + int temp = matrix[i, j]; + matrix[i, j] = matrix[i, matrix.GetLength(1) - 1 - j]; + matrix[i, matrix.GetLength(1) - 1 - j] = temp; + } + } // end } public void Task10(int[,] matrix) { + if (matrix == null || matrix.GetLength(0) != matrix.GetLength(1)) + return; // code here - + int n = matrix.GetLength(0); // Tamaño de la matriz cuadrada + int mitad = n / 2; + + // Si es impar, incluir la fila del medio + if (n % 2 != 0) + mitad++; + + for (int i = mitad; i < n; i++) + { + for (int j = 0; j < n; j++) + { + // Llenar solo elementos a la izquierda o en la diagonal principal + if (j <= i) + { + matrix[i, j] = 1; + } + } + } // end - } public int[,] Task11(int[,] matrix) { int[,] answer = null; // code here - + if (matrix == null) + return new int[0, 0]; + + int filas = matrix.GetLength(0); + int columnas = matrix.GetLength(1); + + // Primero contamos cuántas filas no tienen ceros + int filasBuenas = 0; + for (int i = 0; i < filas; i++) + { + bool tieneCero = false; + for (int j = 0; j < columnas; j++) + { + if (matrix[i, j] == 0) + { + tieneCero = true; + break; + } + } + if (!tieneCero) filasBuenas++; + } + + // Creamos la matriz respuesta + answer = new int[filasBuenas, columnas]; + int filaActual = 0; + + // Copiamos solo las filas buenas + for (int i = 0; i < filas; i++) + { + bool tieneCero = false; + for (int j = 0; j < columnas; j++) + { + if (matrix[i, j] == 0) + { + tieneCero = true; + break; + } + } + + if (!tieneCero) + { + // Copiar esta fila completa + for (int j = 0; j < columnas; j++) + { + answer[filaActual, j] = matrix[i, j]; + } + filaActual++; + } + } // end return answer; } public void Task12(int[][] array) { + if (array == null) return; // code here - + // Método burbuja simple para ordenar + for (int i = 0; i < array.Length - 1; i++) + { + for (int j = 0; j < array.Length - 1 - i; j++) + { + // Calcular suma de la fila j + int sumaActual = 0; + if (array[j] != null) + { + foreach (int num in array[j]) + sumaActual += num; + } + + // Calcular suma de la fila j+1 + int sumaSiguiente = 0; + if (array[j + 1] != null) + { + foreach (int num in array[j + 1]) + sumaSiguiente += num; + } + + // Si la suma actual es mayor, intercambiar filas + if (sumaActual > sumaSiguiente) + { + int[] temp = array[j]; + array[j] = array[j + 1]; + array[j + 1] = temp; + } + } + } // end - } } -} \ No newline at end of file +} From 06f668b903ff8d2554381c1c8f08dfdc4d9c769e Mon Sep 17 00:00:00 2001 From: Ezequiel Alejandro Zapata <157446504+Ezequiel-A-Zapata@users.noreply.github.com> Date: Sun, 21 Dec 2025 03:36:19 +0300 Subject: [PATCH 4/5] Update White2.cs --- Lab5/White.cs | 62 ++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/Lab5/White.cs b/Lab5/White.cs index 6fce95f..8b92dea 100644 --- a/Lab5/White.cs +++ b/Lab5/White.cs @@ -34,12 +34,13 @@ public double Task1(int[,] matrix) } public (int row, int col) Task2(int[,] matrix) { + + // code here int row = 0, col = 0; int element = matrix[0,0]; - // code here for (int i = 0; i < matrix.GetLength(0); i++) { - for (int j = 0; j < matrix.GetLength(1) - 1; j++) + for (int j = 0; j < matrix.GetLength(1); j++) { if (matrix[i,j] < element) { @@ -58,25 +59,26 @@ public void Task3(int[,] matrix, int k) { // code here - int maxNum = matrix[0, k]; - int maxRow = 0; + int firstnum = matrix[0, k]; + int row = 0; + for (int i = 0; i < matrix.GetLength(0); i++) { - if (matrix[i, k] > maxNum) + if (matrix[i, k] > firstnum) { - maxNum = matrix[i, k]; - maxRow = i; + firstnum = matrix[i, k]; + row = i; } } - if (maxRow == 0) + if ( firstnum != matrix[0,k]) { - return; - } - for (int j = 0; j < matrix.GetLength(1); j++) - { - int temp = matrix[0, j]; - matrix[0, j] = matrix[maxRow, j]; - matrix[maxRow, j] = temp; + for( int j = 0; j < matrix.GetLength(1); j++) + { + int temp = matrix[0, j]; + matrix[0, j] = matrix[row, j]; + matrix[row, j] = temp; + + } } // end @@ -131,10 +133,14 @@ public int Task5(int[,] matrix) int sum = 0; // code here - for (int i = 0; i < matrix.GetLength(0); i++) + if (matrix.GetLength(0) == matrix.GetLength(1)) { - sum += matrix[i, i]; + for (int i = 0; i < matrix.GetLength(0); i++) + { + sum += matrix[i, i]; + } } + // end return sum; @@ -206,7 +212,6 @@ public int[] Task7(int[,] matrix) // code here if (matrix == null) { - negatives = new int[0]; return negatives; } @@ -226,7 +231,7 @@ public int[] Task7(int[,] matrix) // Si no hay negativos, retornar array vacío if (count == 0) { - negatives = new int[0]; + return negatives; } else { @@ -325,22 +330,12 @@ public void Task10(int[,] matrix) return; // code here - int n = matrix.GetLength(0); // Tamaño de la matriz cuadrada - int mitad = n / 2; - - // Si es impar, incluir la fila del medio - if (n % 2 != 0) - mitad++; - - for (int i = mitad; i < n; i++) + int n = matrix.GetLength(0); + for ( int i = n/2; i < matrix.GetLength(0); i++ ) { - for (int j = 0; j < n; j++) + for (int j = 0; j <= i; j++) { - // Llenar solo elementos a la izquierda o en la diagonal principal - if (j <= i) - { - matrix[i, j] = 1; - } + matrix[i, j] = 1; } } // end @@ -442,3 +437,4 @@ public void Task12(int[][] array) } } } + From f2492655c2961ea806ce2ef55c74ce7701866ffc Mon Sep 17 00:00:00 2001 From: Ezequiel Alejandro Zapata <157446504+Ezequiel-A-Zapata@users.noreply.github.com> Date: Sun, 21 Dec 2025 04:05:25 +0300 Subject: [PATCH 5/5] Update White3.cs --- Lab5/White.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lab5/White.cs b/Lab5/White.cs index 8b92dea..ddb9733 100644 --- a/Lab5/White.cs +++ b/Lab5/White.cs @@ -59,6 +59,15 @@ public void Task3(int[,] matrix, int k) { // code here + if (matrix == null) + return; + if (k < 0 || k >= matrix.GetLength(1)) + return; + int rows = matrix.GetLength(0); + int cols = matrix.GetLength(1); + + if (rows == 0 || cols == 0) return; + int firstnum = matrix[0, k]; int row = 0; @@ -438,3 +447,4 @@ public void Task12(int[][] array) } } +