This commit is contained in:
Anastasia Yazykova 2024-07-05 15:06:26 +04:00
parent 2f653c0f17
commit 2666193376

View File

@ -158,24 +158,29 @@ namespace Practika
case 2: case 2:
int maxN = -1; int maxN = -1;
int minP = -1; int minP = -1;
int f = 0;
for (int i = 0; i < array1.Length; i++) for (int i = 0; i < array1.Length; i++)
{ {
if (array1[i] < 0) if (array1[i] < 0)
{ {
if (maxN == -1 || array1[i] < array1[maxN])
{
maxN = i; maxN = i;
} break;
}
else if (minP == -1 || array1[i] > 0)
{
if (minP == -1 || array1[i] < array1[minP])
{
minP = i;
}
} }
} }
for (int i =array1.Length-1;i>=0;i--)
{
if (array1[i]>0 && f<2)
{
f++;
minP = i;
break;
}
}
if (maxN != -1 && minP != -1) if (maxN != -1 && minP != -1)
{ {
int q = array1[maxN]; int q = array1[maxN];
@ -188,26 +193,35 @@ namespace Practika
textBoxEnd.Text += array1[i].ToString() + " "; textBoxEnd.Text += array1[i].ToString() + " ";
} }
break; break;
case 3: case 3:
int n = array1.Length; int n = array1.Length;
int l = -1; 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; 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[i] = array1[i - 1];
} }
array1[l + 1] = -1;
array1[l] = 0;
textBoxEnd.Text = string.Join(" ", array1); textBoxEnd.Text = string.Join(" ", array1);
@ -217,21 +231,22 @@ namespace Practika
case 4: case 4:
int w = Array1size ; int w = Array1size;
int o = 0;
for (int i = 0; i <w; i++) for (int i = w-1; i >= 0; i--)
{ {
if (array1[i]%2 == 0 && o==0) if (array1[i] % 2 != 0 )
{ {
o++;
for (int j = i; j < w - 1; j++) for (int j = i; j < w - 1; j++)
{ {
array1[j] = array1[j + 1]; array1[j] = array1[j + 1];
} }
w--; w--;
i--; break;
} }
} }
for (int i = 0; i < w; i++) for (int i = 0; i < w; i++)
{ {
@ -240,73 +255,79 @@ namespace Practika
break; break;
case 5: case 5:
int maxPosValue = int.MinValue; int minn =int.MaxValue;
int columnToDelete = -1; int rowToDelete = -1;
for (int j = 0; j < CountLine; j++) 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] <minn && array2[i, j]>0)
{ {
maxPosValue = array2[i, j]; minn= array2[i, j];
columnToDelete = 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 j = 0; j < CountLine; j++)
for (int i = 0; i < Count; i++)
{
for (int j = 0; j < CountLine - 1; 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; break;
case 6: case 6:
int minElement = int.MaxValue; int max = int.MinValue;
int rowWithMinElement = -1; int r = -1;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
for (int j = 0; j < CountLine; j++) for (int j = 0; j < CountLine; j++)
{ {
if (array2[i, j] < minElement) if (array2[i, j] > max)
{ {
minElement = array2[i, j]; max = array2[i, j];
rowWithMinElement = i; r = i;
} }
} }
} }
for (int j = 0; j <Count - 1; j++) for (int j = 0; j < Count - 1; j++)
{ {
for (int k = 0; k < CountLine- 1 - j; k++) for (int k = 0; k < CountLine - 1 - j; k++)
{ {
if (array2[rowWithMinElement, k] > array2[rowWithMinElement, k + 1]) if (array2[r, k] < array2[r, k + 1])
{ {
for (int i = 0; i <Count; i++)
for (int i = 0; i < Count; i++)
{ {
int ww = array2[i, k]; int q = array2[i, k];
array2[i, k] = array2[i, k + 1]; array2[i, k] = array2[i, k + 1];
array2[i, k + 1] =ww; array2[i, k + 1] = q;
} }
} }
} }
} }
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
for (int j = 0; j < CountLine; j++) for (int j = 0; j < CountLine; j++)
@ -315,11 +336,6 @@ namespace Practika
} }
textBoxEnd.Text += Environment.NewLine; textBoxEnd.Text += Environment.NewLine;
} }
break; break;
} }
@ -407,7 +423,7 @@ namespace Practika
private void button3_Click(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e)
{ {
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü"; textBoxTask.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ ðàçìåðà N. Âñòàâèòü 0 ïåðåä\r\nïîñëåäíèì íå÷åòíûì ýëåìåíòîì ìàññèâà";
Task = 3; Task = 3;
textBoxEnd.Clear(); textBoxEnd.Clear();
@ -415,14 +431,14 @@ namespace Practika
private void button4_Click(object sender, EventArgs e) private void button4_Click(object sender, EventArgs e)
{ {
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü"; textBoxTask.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ ðàçìåðà N. Óäàëèòü èç ìàññèâà\r\nïîñëåäíèé íå÷åòíûé (íå÷åòíûé ïî çíà÷åíèþ, à íå ïî ïîðÿäêîâîìó\r\níîìåðó) ýëåìåíò";
Task = 4; Task = 4;
textBoxEnd.Clear(); textBoxEnd.Clear();
} }
private void button5_Click(object sender, EventArgs e) private void button5_Click(object sender, EventArgs e)
{ {
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü"; textBoxTask.Text = "Äàí öåëî÷èñëåííûé äâóìåðíûé ìàññèâ ðàçìåðà N*N. Óäàëèòü ñòðîêó,\r\nñîäåðæàùèé ìèíèìàëüíîå ïîëîæèòåëüíîå";
Task = 5; Task = 5;
textBoxEnd.Clear(); textBoxEnd.Clear();
@ -430,7 +446,7 @@ namespace Practika
private void button6_Click(object sender, EventArgs e) private void button6_Click(object sender, EventArgs e)
{ {
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü"; textBoxTask.Text = "Äàí öåëî÷èñëåííûé äâóìåðíûé ìàññèâ ðàçìåðà N*N. Îòñîðòèðîâàòü ïî\r\nóáûâàíèþ ñòîëáöû ìàòðèöû ïî ñòðîêå, ñîäåðæàùåé ìàêñèìàëüíûé\r\nýëåìåíò ìàòðèöû.";
Task = 6; Task = 6;
textBoxEnd.Clear(); textBoxEnd.Clear();
} }