This commit is contained in:
Anastasia Yazykova 2024-06-29 01:02:43 +04:00
parent 9927fa2d86
commit 8b96d51da8
2 changed files with 272 additions and 108 deletions

View File

@ -36,24 +36,24 @@
button2 = new Button();
button1 = new Button();
panel2 = new Panel();
label3 = new Label();
label2 = new Label();
label1 = new Label();
textBoxMax = new TextBox();
textBoxMin = new TextBox();
button11 = new Button();
textBoxNumber = new TextBox();
textBoxTake = new TextBox();
textBoxMassive = new TextBox();
button10 = new Button();
button9 = new Button();
button8 = new Button();
button7 = new Button();
button9 = new Button();
panel3 = new Panel();
label5 = new Label();
label4 = new Label();
textBoxTask = new TextBox();
textBoxEnd = new TextBox();
button11 = new Button();
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
label5 = new Label();
panel1.SuspendLayout();
panel2.SuspendLayout();
panel3.SuspendLayout();
@ -80,6 +80,7 @@
button6.TabIndex = 5;
button6.Text = "button6";
button6.UseVisualStyleBackColor = true;
button6.Click += button6_Click;
//
// button5
//
@ -89,6 +90,7 @@
button5.TabIndex = 4;
button5.Text = "button5";
button5.UseVisualStyleBackColor = true;
button5.Click += button5_Click;
//
// button4
//
@ -98,6 +100,7 @@
button4.TabIndex = 3;
button4.Text = "button4";
button4.UseVisualStyleBackColor = true;
button4.Click += button4_Click;
//
// button3
//
@ -107,6 +110,7 @@
button3.TabIndex = 2;
button3.Text = "button3";
button3.UseVisualStyleBackColor = true;
button3.Click += button3_Click;
//
// button2
//
@ -116,6 +120,7 @@
button2.TabIndex = 1;
button2.Text = "button2";
button2.UseVisualStyleBackColor = true;
button2.Click += button2_Click;
//
// button1
//
@ -146,6 +151,34 @@
panel2.Size = new Size(857, 368);
panel2.TabIndex = 1;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(383, 24);
label3.Name = "label3";
label3.Size = new Size(72, 25);
label3.TabIndex = 12;
label3.Text = "Размер";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(420, 137);
label2.Name = "label2";
label2.Size = new Size(35, 25);
label2.TabIndex = 11;
label2.Text = "До";
label2.Click += label2_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(263, 137);
label1.Name = "label1";
label1.Size = new Size(33, 25);
label1.TabIndex = 10;
label1.Text = "От";
//
// textBoxMax
//
textBoxMax.Location = new Point(461, 125);
@ -162,6 +195,16 @@
textBoxMin.Size = new Size(82, 38);
textBoxMin.TabIndex = 8;
//
// button11
//
button11.Location = new Point(530, 255);
button11.Name = "button11";
button11.Size = new Size(119, 103);
button11.TabIndex = 2;
button11.Text = "Двумерный(Авто)";
button11.UseVisualStyleBackColor = true;
button11.Click += button11_Click_1;
//
// textBoxNumber
//
textBoxNumber.Location = new Point(318, 63);
@ -196,16 +239,6 @@
button10.UseVisualStyleBackColor = true;
button10.Click += button10_Click_1;
//
// button9
//
button9.Location = new Point(461, 119);
button9.Name = "button9";
button9.Size = new Size(123, 42);
button9.TabIndex = 3;
button9.Text = "Создать";
button9.UseVisualStyleBackColor = true;
button9.Click += button9_Click_1;
//
// button8
//
button8.Location = new Point(190, 255);
@ -226,6 +259,16 @@
button7.UseVisualStyleBackColor = true;
button7.Click += button7_Click_1;
//
// button9
//
button9.Location = new Point(461, 119);
button9.Name = "button9";
button9.Size = new Size(123, 42);
button9.TabIndex = 3;
button9.Text = "Создать";
button9.UseVisualStyleBackColor = true;
button9.Click += button9_Click_1;
//
// panel3
//
panel3.Controls.Add(label5);
@ -238,6 +281,24 @@
panel3.Size = new Size(854, 287);
panel3.TabIndex = 2;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(602, 19);
label5.Name = "label5";
label5.Size = new Size(89, 25);
label5.TabIndex = 12;
label5.Text = "Результат";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(22, 19);
label4.Name = "label4";
label4.Size = new Size(79, 25);
label4.TabIndex = 11;
label4.Text = "Задание";
//
// textBoxTask
//
textBoxTask.Location = new Point(22, 47);
@ -254,62 +315,6 @@
textBoxEnd.Size = new Size(203, 206);
textBoxEnd.TabIndex = 6;
//
// button11
//
button11.Location = new Point(530, 255);
button11.Name = "button11";
button11.Size = new Size(119, 103);
button11.TabIndex = 2;
button11.Text = "Двумерный(Авто)";
button11.UseVisualStyleBackColor = true;
button11.Click += button11_Click_1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(263, 137);
label1.Name = "label1";
label1.Size = new Size(33, 25);
label1.TabIndex = 10;
label1.Text = "От";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(420, 137);
label2.Name = "label2";
label2.Size = new Size(35, 25);
label2.TabIndex = 11;
label2.Text = "До";
label2.Click += label2_Click;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(383, 24);
label3.Name = "label3";
label3.Size = new Size(72, 25);
label3.TabIndex = 12;
label3.Text = "Размер";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(22, 19);
label4.Name = "label4";
label4.Size = new Size(79, 25);
label4.TabIndex = 11;
label4.Text = "Задание";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(602, 19);
label5.Name = "label5";
label5.Size = new Size(89, 25);
label5.TabIndex = 12;
label5.Text = "Результат";
//
// Form1
//
AutoScaleDimensions = new SizeF(10F, 25F);

View File

@ -25,7 +25,7 @@ namespace Practika
private void button1_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ N îïðåäåëèòü ìàêñèìàëüíîå êîëè÷åñòâî åãî îäèíàêîâûõ ýëåìåíòîâ";
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü";
Task = 1;
textBoxEnd.Clear();
}
@ -36,30 +36,54 @@ namespace Practika
{
textBoxMassive.Clear();
string input = textBoxTake.Text;
string[] numbers = input.Split(' ');
Array1size = numbers.Length;
array1 = new int[Array1size];
for (int i = 0; i < Array1size; i++)
if (Task == 3)
{
if (int.TryParse(numbers[i], out int number))
string input = textBoxTake.Text;
string[] numbers = input.Split(' ');
Array1size = numbers.Length;
array1 = new int[Array1size +1];
for (int i = 0; i < Array1size; i++)
{
array1[i] = number;
if (int.TryParse(numbers[i], out int number))
{
array1[i] = number;
}
else
{
MessageBox.Show("!");
return;
}
}
else
for (int i = 0; i < Array1size; i++)
{
MessageBox.Show("Îøèáêà !");
return;
textBoxMassive.Text += array1[i].ToString() + " ";
}
}
for (int i = 0; i < Array1size; i++)
else
{
textBoxMassive.Text += array1[i].ToString() + " ";
string input = textBoxTake.Text;
string[] numbers = input.Split(' ');
Array1size = numbers.Length;
array1 = new int[Array1size+1];
for (int i = 0; i < Array1size; i++)
{
if (int.TryParse(numbers[i], out int number))
{
array1[i] = number;
}
else
{
MessageBox.Show("Îøèáêà !");
return;
}
}
for (int i = 0; i < Array1size; i++)
{
textBoxMassive.Text += array1[i].ToString() + " ";
}
}
}
private void button8_Click_1(object sender, EventArgs e)
@ -108,38 +132,134 @@ namespace Practika
{
case 1:
int Maxx = 0;
Dictionary<int, int> c;
c = new Dictionary<int, int>();
foreach (int i in array1)
int g = -1;
for (int i = 1; i < array1.Length; i++)
{
if (c.ContainsKey(i))
if ((array1[i] % 2 == 0 && array1[i - 1] % 2 == 0) ||
(array1[i] % 2 != 0 && array1[i - 1] % 2 != 0))
{
c[i]++;
}
else
{
c[i] = 1;
g = i;
break;
}
}
Maxx = c.Max(x => x.Value);
textBoxEnd.Text += "Màêñèìàëüíîå êîëè÷åñòâî îäèíàêîâûõ ýëåìåíòîâ " + Maxx.ToString();
if (g == -1)
{
g = 0;
}
textBoxEnd.Text += g.ToString();
break;
case 2:
int maxN = -1;
int minP = -1;
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;
}
}
}
if (maxN != -1 && minP != -1)
{
int q = array1[maxN];
array1[maxN] = array1[minP];
array1[minP] = q;
}
for (int i = 0; i < array1.Length; i++)
{
textBoxEnd.Text += array1[i].ToString() + " ";
}
break;
case 3:
int n = array1.Length;
int l = -1;
for (int i = 0; i < n; i++)
{
if (array1[i] > 0)
{
l= i;
}
}
for (int i = n - 1; i > l+1; i--)
{
array1[i] = array1[i - 1];
}
if (l + 1 <= n)
{
array1[l+ 1] = -1;
}
textBoxEnd.Text = string.Join(" ", array1);
break;
case 4:
break;
case 5 :
break;
case 6:
break;
}
}
private void button10_Click_1(object sender, EventArgs e)
{
textBoxMassive.Clear();
Array1size = Int32.Parse(textBoxNumber.Text);
array1 = new int[Array1size];
Min = Int32.Parse(textBoxMin.Text);
Max = Int32.Parse(textBoxMax.Text);
for (int i = 0; i < Array1size; i++)
if (Task == 3)
{
array1[i] = random.Next(Min, Max);
textBoxMassive.Clear();
Array1size = Int32.Parse(textBoxNumber.Text);
array1 = new int[Array1size+1];
Min = Int32.Parse(textBoxMin.Text);
Max = Int32.Parse(textBoxMax.Text);
for (int i = 0; i < Array1size; i++)
{
array1[i] = random.Next(Min, Max);
}
for (int i = 0; i < array1.Length-1; i++)
{
textBoxMassive.Text += array1[i].ToString() + " ";
}
}
textBoxMassive.Text = string.Join(", ", array1);
else
{
textBoxMassive.Clear();
Array1size = Int32.Parse(textBoxNumber.Text);
array1 = new int[Array1size];
Min = Int32.Parse(textBoxMin.Text);
Max = Int32.Parse(textBoxMax.Text);
for (int i = 0; i < Array1size; i++)
{
array1[i] = random.Next(Min, Max);
}
textBoxMassive.Text = string.Join(", ", array1);
}
}
private void button11_Click_1(object sender, EventArgs e)
@ -174,8 +294,47 @@ namespace Practika
private void label2_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ ðàçìåðà N. Ïîìåíÿòü ìåñòàìè\r\nïåðâûé îòðèöàòåëüíûé ýëåìåíò è ïðåäïîñëåäíèé ïîëîæèòåëüíûé";
Task = 2;
textBoxEnd.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü";
Task = 3;
textBoxEnd.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü";
Task = 4;
textBoxEnd.Clear();
}
private void button5_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü";
Task = 5;
textBoxEnd.Clear();
}
private void button6_Click(object sender, EventArgs e)
{
textBoxTask.Text = "Äàí îäíîìåðíûé ìàññèâ íåíóëåâûõ öåëûõ ÷èñåë ðàçìåðà N. Ïðîâåðèòü,\r\n÷åðåäóþòñÿ ëè â íåì ÷åòíûå è íå÷åòíûå ÷èñëà. Åñëè ÷åðåäóþòñÿ, òî\r\nâûâåñòè 0, åñëè íåò, òî âûâåñòè íîìåð ïåðâîãî ýëåìåíòà, íàðóøàþùåãî\r\nçàêîíîìåðíîñòü";
Task = 6;
textBoxEnd.Clear();
}
}
}