From 26661933768fb368bb6fed831ac885a74e39f43e Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Fri, 5 Jul 2024 15:06:26 +0400 Subject: [PATCH] b --- Practika/Practika/Form1.cs | 148 ++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 66 deletions(-) diff --git a/Practika/Practika/Form1.cs b/Practika/Practika/Form1.cs index 9d96746..40087e4 100644 --- a/Practika/Practika/Form1.cs +++ b/Practika/Practika/Form1.cs @@ -158,24 +158,29 @@ namespace Practika case 2: int maxN = -1; int minP = -1; + int f = 0; for (int i = 0; i < array1.Length; i++) { if (array1[i] < 0) { - if (maxN == -1 || array1[i] < array1[maxN]) - { - maxN = i; - } - } - else if (minP == -1 || array1[i] > 0) - { - if (minP == -1 || array1[i] < array1[minP]) - { - minP = i; - } + + + maxN = i; + break; + } } + for (int i =array1.Length-1;i>=0;i--) + { + if (array1[i]>0 && f<2) + { + f++; + minP = i; + break; + } + } + if (maxN != -1 && minP != -1) { int q = array1[maxN]; @@ -188,26 +193,35 @@ namespace Practika textBoxEnd.Text += array1[i].ToString() + " "; } break; + case 3: int n = array1.Length; int l = -1; - for (int i = 0; i < n; i++) + for (int i = array1.Length-1; i>=0; i--) { - if (array1[i] < 0 && l != 0) + if (array1[i] % 2 != 0) { l = i; + break; + + } + + } + if (l==-1) + { + { + MessageBox.Show("Ошибка !"); + return; } } - - for (int i = n - 1; i > l + 1; i--) + for (int i = n - 1; i > l - 1; i--) { array1[i] = array1[i - 1]; } + - - array1[l + 1] = -1; - + array1[l] = 0; textBoxEnd.Text = string.Join(" ", array1); @@ -217,21 +231,22 @@ namespace Practika case 4: - int w = Array1size ; - int o = 0; - for (int i = 0; i = 0; i--) { - if (array1[i]%2 == 0 && o==0) + if (array1[i] % 2 != 0 ) { - o++; + for (int j = i; j < w - 1; j++) { array1[j] = array1[j + 1]; } w--; - i--; + break; } + } for (int i = 0; i < w; i++) { @@ -240,73 +255,79 @@ namespace Practika break; case 5: - int maxPosValue = int.MinValue; - int columnToDelete = -1; - for (int j = 0; j < CountLine; j++) + int minn =int.MaxValue; + int rowToDelete = -1; + for (int i = 0; i < Count; i++) { - for (int i = 0; i < Count; i++) + for (int j = 0; j < CountLine; j++) { - if (array2[i, j] > maxPosValue && array2[i, j] < 0) + if (array2[i, j] 0) { - maxPosValue = array2[i, j]; - columnToDelete = j; + minn= array2[i, j]; + rowToDelete = i; } } } - for (int j = columnToDelete; j < CountLine - 1; j++) + + if (rowToDelete != -1) { - for (int i = 0; i < Count; i++) + for (int i = rowToDelete; i < Count - 1; i++) { - array2[i, j] = array2[i, j + 1]; + for (int j = 0; j < CountLine; j++) + { + array2[i, j] = array2[i + 1, j]; + } } - } - for (int i = 0; i < Count; i++) - { - array2[i, Count - 1] = 0; - } - - for (int i = 0; i < Count; i++) - { - for (int j = 0; j < CountLine - 1; j++) + for (int j = 0; j < CountLine; j++) { - textBoxEnd.Text += array2[i, j].ToString() + " "; + array2[Count - 1, j] = 0; + } + for (int i = 0; i < Count - 1; i++) + { + for (int j = 0; j < Count; j++) + { + textBoxEnd.Text += array2[i, j].ToString() + " "; + } + textBoxEnd.Text += Environment.NewLine; } - textBoxEnd.Text += Environment.NewLine; - } + } break; case 6: - int minElement = int.MaxValue; - int rowWithMinElement = -1; + int max = int.MinValue; + int r = -1; for (int i = 0; i < Count; i++) { for (int j = 0; j < CountLine; j++) { - if (array2[i, j] < minElement) + if (array2[i, j] > max) { - minElement = array2[i, j]; - rowWithMinElement = i; + max = array2[i, j]; + r = i; } } } - for (int j = 0; j array2[rowWithMinElement, k + 1]) + if (array2[r, k] < array2[r, k + 1]) { - for (int i = 0; i