From 7715130ec4148fc5fe6d7dee5ce761b5387aef94 Mon Sep 17 00:00:00 2001 From: Khanhlinh2406 Date: Sun, 21 Dec 2025 23:18:11 +0300 Subject: [PATCH 1/4] Update White.cs --- Lab6/White.cs | 335 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 320 insertions(+), 15 deletions(-) diff --git a/Lab6/White.cs b/Lab6/White.cs index 0a2eed78..1a59f31d 100644 --- a/Lab6/White.cs +++ b/Lab6/White.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Linq; +using System.Net.Http.Headers; using System.Runtime.InteropServices; namespace Lab6 @@ -9,91 +10,395 @@ public void Task1(double[] A, double[] B) { // code here + int maxA = FindMaxIndex(A); + int maxB = FindMaxIndex(B); + double sum = 0; + double m = 0; + double count = 0; + if (((A.Length - maxA) >= (B.Length - maxB)) && maxA != A.Length) + { + for (int i = maxA + 1; i < A.Length; i++) + { + sum += A[i]; + count++; + } + m = sum / count; + A[maxA] = m; + } + else if (((A.Length-maxA) >= (B.Length-maxB)) && maxB != B.Length) + { + for (int i = maxB + 1; i < B.Length; i++) + { + sum += B[i]; + count++; + } + m = sum / count; + count++; + } // end } + public int FindMaxIndex(double[] array) + { + double max = double.MinValue; + int maxi = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] > max) + { + max = array[i]; + maxi = i; + } + } + return maxi; + } public void Task2(int[,] A, int[,] B) { // code here - + int rowA = FindMaxRowIndexInColumn(A, 1); + int rowB = FindMaxRowIndexInColumn(B, 1); + if (A.GetLength(0) == B.GetLength(0) && A.GetLength(1) == B.GetLength(1)) + { + for (int j= 0; j< A.GetLength(1); j++) + { + (A[rowA, j], B[rowB, j]) = (B[rowB, j], A[rowA, j]); + } + } // end } + public int FindMaxRowIndexInColumn(int[,]matrix,int col) + { + int max = int.MinValue; + int maxi = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (matrix[i, col] > matrix[maxi, col]) + { + max = matrix[i, col]; + maxi = i; + } + } + return maxi; + } public int Task3(int[,] matrix) { int answer = 0; // code here - + int[] negative = GetNegativeCountPerRow(matrix); + int maxi = 0; + for (int i = 0; i < negative.Length; i++) + { + if (negative[i] > negative[maxi]) + { + maxi = i; + } + } + answer = maxi; // end return answer; } + public int[] GetNegativeCountPerRow(int[,] matrix) + { + int[] newMatrix = new int[matrix.GetLength(0)]; + int count = 0; + int n = matrix.GetLength(0); + int m = matrix.GetLength(1); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) + { + if (matrix[i, j] < 0) + { + count++; + } + } + newMatrix[i] = count; + } + return newMatrix; + } public void Task4(int[,] A, int[,] B) { // code here - + int rowA, colA; + int rowB, colB; + int maxA = FindMax(A, out rowA, out colA); + int maxB = FindMax(B, out rowB, out colB); + (A[rowA, colA], B[rowB,colB]) = (B[rowB,colB], A[rowA, colA]); // end } + public int FindMax(int[,] matrix,out int row,out int col) + { + row = 0; + col = 0; + int max = int.MinValue; + int n = matrix.GetLength(0); + int m = matrix.GetLength(1); + for (int i = 0; i < n; i++) + { + for (int j = 0;j matrix[row, col]) + { + row = i; + col = j; + max = matrix[i, j]; + } + } + } + return max; + } public void Task5(int[,] A, int[,] B) { // code here - + int rowA, rowB, colA, colB; + int maxA = FindMax(A, out rowA, out colA); + int maxB = FindMax(B, out rowB, out colB); + if (A.GetLength(0) == B.GetLength(0)) + { + SwapColumns(A, colA, B, colB); + } // end } + public void SwapColumns(int[,]A,int colIndexA, int[,]B,int colIndexB) + { + for (int i = 0; i< A.GetLength(0); i++) + { + (A[i, colIndexA], B[i, colIndexB]) = (B[i,colIndexB],A[i,colIndexA]); + } + } public void Task6(int[,] matrix, Sorting sort) { // code here - + sort(matrix); // end } + public delegate void Sorting(int[,] matrix); + public void SortDiagonalAscending(int[,] matrix) + { + int[] newMatrix = new int[matrix.GetLength(0)]; + if (matrix.GetLength(0) == matrix.GetLength(1)) + { + for (int i = 0;i < matrix.GetLength(0); i++) + { + newMatrix[i] = matrix[i, i]; + } + for (int i = 0; i < matrix.GetLength(0)-1; i++) + { + for (int j = 0; i < matrix.GetLength(0) - i - 1; j++) + { + if (newMatrix[j] > newMatrix[j + 1]) + { + int temp = newMatrix[j]; + newMatrix[j] = newMatrix[j + 1]; + newMatrix[j + 1] = temp; + } + } + } + for (int i = 0; i < matrix.GetLength(0); i++) + { + matrix[i,i] = newMatrix[i]; + } + } + } + public void SortDiagonalDescending(int[,] matrix) + { + int[] newMatrix = new int[matrix.GetLength(0)]; + if (matrix.GetLength(0) == matrix.GetLength(1)) + { + for (int i = 0; i < matrix.GetLength(0); i++) + { + newMatrix[i] = matrix[i, i]; + } + for (int i = 0; i < matrix.GetLength(0) - 1; i++) + { + for (int j = 0; i < matrix.GetLength(0) - i - 1; j++) + { + if (newMatrix[j] > newMatrix[j + 1]) + { + (newMatrix[j], newMatrix[j + 1]) = (newMatrix[j + 1], newMatrix[i]); + } + } + } + for (int i = 0; i < matrix.GetLength(0); i++) + { + matrix[i, i] = newMatrix[i]; + } + } + } public long Task7(int n, int k) { long answer = 0; // code here - + if (n >= k) + { + answer = Factorial(n) / (Factorial(k) * Factorial(n - k)); + } + else + answer = 0; // end return answer; } + public long Factorial(int n) + { + if (n <= 1) + { + return 1; + } + else + { + return n * Factorial(n - 1); + } + } public double Task8(double v, double a, BikeRide ride) { double answer = 0; // code here + if (v == 0 && a == 0) + { + return 0; + } + else + { + answer = ride(v, a); + } + // end - // end - - return answer; + return answer; + } + public delegate double BikeRide(double v, double a); + public double GetDistance(double v, double a) + { + double distance = 0; + for (int i = 0; i < 10; i++) + { + distance += v+a*i; + } + return distance; + } + public double GetTime(double v , double a) + { + double distance = v; + double time = 0; + while (distance < 100) + { + distance += v + a * distance; + time++; + } + return time; } public int Task9(int[][] array) { int answer = 0; // code here + Swapper swap; + if (array.Length % 2 == 0) + { + swap = SwapFromLeft; + } + else + { + swap = SwapFromRight; + } + for (int i = 0; i < array.Length; i++) + { + swap(array[i]); + answer += GetSum(array[i]); + } + // end - // end - - return answer; + return answer; + } + public delegate void Swapper(int[] array); + public int GetSum(int[] array) + { + int sum = 0; + for (int i = 1;i0 ; i -= 2) + { + (array[i], array[i - 1]) = (array[i - 1], array[i]); + } } public int Task10(int[][] array, Func func) { int answer = 0; // code here - + answer = func(array); // end return answer; } + public delegate int Func(int[][] array); + public int CountPositive(int[][] array) + { + int count = 0; + for (int i = 0; i < array.Length; i++) + { + for (int j = 0; j < array[i].Length; j++) + { + if (array[i][j] > 0) + { + count++; + } + } + } + return count; + } + public int FindMax(int[][] array) + { + int max = int.MinValue; + for (int i = 0; i < array.Length; i++) + { + for (int j = 0; j < array[i].Length; j++) + { + if (array[i][j] > max) + { + max = array[i][j]; + } + } + } + return max; + } + public int FindMaxRowLength(int[][] array) + { + int max1 = 0; + for(int i = 0; i < array[0].Length; i++) + { + if (array[i].Length > max1) + { + max1= array[i].Length; + } + } + return max1; + } } -} \ No newline at end of file +} From 87692893e6f145ecde79ff6bb4faf8947c935a1a Mon Sep 17 00:00:00 2001 From: Khanhlinh2406 Date: Sun, 21 Dec 2025 23:24:25 +0300 Subject: [PATCH 2/4] Update Blue.cs --- Lab6/Blue.cs | 93 ---------------------------------------------------- 1 file changed, 93 deletions(-) diff --git a/Lab6/Blue.cs b/Lab6/Blue.cs index 067ce526..d3f5a12f 100644 --- a/Lab6/Blue.cs +++ b/Lab6/Blue.cs @@ -1,94 +1 @@ -namespace Lab6 -{ - public class Blue - { - public void Task1(ref int[,] matrix) - { - // code here - - // end - - } - public int Task2(int[,] A, int[,] B, int[,] C) - { - int answer = 0; // 1 - increasing 0 - no sequence -1 - decreasing - - // code here - - // end - - return answer; - } - public void Task3(ref int[,] matrix, Func method) - { - - // code here - - // end - - } - public void Task4(ref int[,] matrix) - { - - // code here - - // end - - } - public void Task5(ref int[,] matrix, Finder find) - { - - // code here - - // end - - } - public void Task6(int[,] matrix, SortRowsStyle sort) - { - - // code here - - // end - - } - public void Task7(int[,] matrix, ReplaceMaxElements transform) - { - - // code here - - // end - - } - public double[,] Task8(double a, double b, double h, Func getSum, Func getY) - { - double[,] answer = null; - - // code here - - // end - - return answer; - } - public int Task9(int[,] matrix, GetTriangle triangle) - { - int answer = 0; - - // code here - - // end - - return answer; - } - public bool Task10(int[][] array, Predicate func) - { - bool res = false; - - // code here - - // end - - return res; - } - } -} \ No newline at end of file From 192075e7d5e7355d4205b344e5682c31db28c178 Mon Sep 17 00:00:00 2001 From: Khanhlinh2406 Date: Sun, 21 Dec 2025 23:24:39 +0300 Subject: [PATCH 3/4] Update Green.cs --- Lab6/Green.cs | 96 --------------------------------------------------- 1 file changed, 96 deletions(-) diff --git a/Lab6/Green.cs b/Lab6/Green.cs index 16b248c3..d3f5a12f 100644 --- a/Lab6/Green.cs +++ b/Lab6/Green.cs @@ -1,97 +1 @@ -using System.Linq; -using System.Runtime.InteropServices; -namespace Lab6 -{ - public class Green - { - public void Task1(ref int[] A, ref int[] B) - { - - // code here - - // end - - } - public void Task2(int[,] matrix, int[] array) - { - - // code here - - // end - - } - public void Task3(int[,] matrix) - { - - // code here - - // end - - } - public void Task4(ref int[,] matrix) - { - - // code here - - // end - - } - public int[] Task5(int[,] matrix) - { - int[] answer = null; - - // code here - - // end - - return answer; - } - public int[] Task6(int[,] A, int[,] B) - { - int[] answer = null; - - // code here - - // end - - return answer; - } - public void Task7(int[,] matrix, Sorting sort) - { - - // code here - - // end - - } - public int Task8(double[] A, double[] B) - { - int answer = 0; - - // code here - - // end - - return answer; - } - public void Task9(int[,] matrix, Action sorter) - { - - // code here - - // end - - } - public double Task10(int[][] array, Func func) - { - double res = 0; - - // code here - - // end - - return res; - } - } -} \ No newline at end of file From eee89e834522848c698a03ae1b34652ba7060a31 Mon Sep 17 00:00:00 2001 From: Khanhlinh2406 Date: Sun, 21 Dec 2025 23:25:50 +0300 Subject: [PATCH 4/4] Update Purple.cs --- Lab6/Purple.cs | 95 -------------------------------------------------- 1 file changed, 95 deletions(-) diff --git a/Lab6/Purple.cs b/Lab6/Purple.cs index 231c75b5..d3f5a12f 100644 --- a/Lab6/Purple.cs +++ b/Lab6/Purple.cs @@ -1,96 +1 @@ -using System; -using System.Security.Cryptography; -using static System.Runtime.InteropServices.JavaScript.JSType; -namespace Lab6 -{ - public class Purple - { - public void Task1(int[,] A, int[,] B) - { - - // code here - - // end - - } - public void Task2(ref int[,] A, int[,] B) - { - - // code here - - // end - - } - public void Task3(int[,] matrix) - { - - // code here - - // end - - } - public void Task4(int[,] A, int[,] B) - { - - // code here - - // end - - } - public void Task5(int[] matrix, Sorting sort) - { - - // code here - - // end - - } - public void Task6(int[,] matrix, SortRowsByMax sort) - { - - // code here - - // end - - } - public int[] Task7(int[,] matrix, FindNegatives find) - { - int[] negatives = null; - - // code here - - // end - - return negatives; - } - public int[,] Task8(int[,] matrix, MathInfo info) - { - int[,] answer = null; - - // code here - - // end - - return answer; - } - public int Task9(double a, double b, double h, Func func) - { - int answer = 0; - - // code here - - // end - - return answer; - } - public void Task10(int[][] array, Action func) - { - - // code here - - // end - - } - } -} \ No newline at end of file