234 lines
7.9 KiB
C#
234 lines
7.9 KiB
C#
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||
|
||
namespace Praktika
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
|
||
}
|
||
int[,] array2D;
|
||
public static int flag = 0;
|
||
private void ButtonOne_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxLen.Text) || string.IsNullOrEmpty(textBoxMin.Text) || string.IsNullOrEmpty(textBoxMax.Text))
|
||
{
|
||
MessageBox.Show("Ïîæàëóéñòà, ââåäèòå âñå íåîáõîäèìûå äàííûå äëÿ ñîçäàíèÿ ìàññèâà.");
|
||
return;
|
||
}
|
||
int[] array = new int[Convert.ToInt32(textBoxLen.Text)];
|
||
Random random = new Random();
|
||
for (int i = 0; i < array.Length; i++)
|
||
{
|
||
array[i] = random.Next(Convert.ToInt32(textBoxMin.Text), Convert.ToInt32(textBoxMax.Text));
|
||
}
|
||
arrayTextBox.Text = string.Join(", ", array);
|
||
}
|
||
|
||
private void ButtonTwo_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxLen.Text) || string.IsNullOrEmpty(textBoxMin.Text) || string.IsNullOrEmpty(textBoxMax.Text))
|
||
{
|
||
MessageBox.Show("Ïîæàëóéñòà, ââåäèòå âñå íåîáõîäèìûå äàííûå äëÿ ñîçäàíèÿ ìàññèâà.");
|
||
return;
|
||
}
|
||
int rows = Convert.ToInt32(textBoxLen.Text);
|
||
int columns = Convert.ToInt32(textBoxLen.Text);
|
||
array2D = new int[rows, columns];
|
||
Random random = new Random();
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
for (int j = 0; j < columns; j++)
|
||
{
|
||
array2D[i, j] = random.Next(Convert.ToInt32(textBoxMin.Text), Convert.ToInt32(textBoxMax.Text));
|
||
}
|
||
}
|
||
// Âûâîä äâóìåðíîãî ìàññèâà â òåêñòîâîå ïîëå
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
for (int j = 0; j < columns; j++)
|
||
{
|
||
|
||
sb.Append(array2D[i, j] + " ");
|
||
}
|
||
sb.AppendLine();
|
||
}
|
||
arrayTextBox.Text = sb.ToString();
|
||
}
|
||
|
||
private void Button1_Click(object sender, EventArgs e)
|
||
{
|
||
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
|
||
int maxLength = 0;
|
||
int seriesStartIndex = 0;
|
||
int seriesLength = 0;
|
||
|
||
for (int i = 1; i < array.Length; i++)
|
||
{
|
||
int currentLength = 1;
|
||
for (int j = i; j < array.Length - 1; j++)
|
||
{
|
||
if (array[j] % array[j - 1] == 0)
|
||
{
|
||
currentLength++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (currentLength > maxLength && currentLength >= 2)
|
||
{
|
||
maxLength = currentLength;
|
||
seriesStartIndex = i - 1;
|
||
seriesLength = currentLength;
|
||
}
|
||
}
|
||
MessageBox.Show($"Ñåðèÿ ñ ìàêñèìàëüíîé äëèíîé íà÷èíàåòñÿ ñ ïîçèöèè {seriesStartIndex} è èìååò äëèíó {seriesLength}");
|
||
flag = 1;
|
||
}
|
||
|
||
private void Button9_Click(object sender, EventArgs e)
|
||
{
|
||
if (flag == 1)
|
||
{
|
||
richTextBox1.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ ðàçìåðà N." +
|
||
"Ñåðèÿ – ýòî ïîñëåäîâàòåëüíîñòü ýëåìåíòîâ ìàññèâà, èäóùèõ äðóã çà äðóãîì." +
|
||
"Êàæäûé ýëåìåíò ñåðèè äåëèëñÿ íàöåëî íà ïðåäûäóùèé.Ñåðèÿ äîëæíà" +
|
||
"ñîäåðæàòü ìèíèìóì 2 ýëåìåíòà.Äëèíà ñåðèè – êîëè÷åñòâî ýëåìåíòîâ â" +
|
||
"ñåðèè.Íàéòè ñåðèþ ñ ìàêñèìàëüíîé äëèíîé.Âûâåñòè ñ êàêîé ïîçèöèè" +
|
||
"íà÷èíàåòñÿ ñåðèÿ è åå äëèíó.";
|
||
}
|
||
else if (flag == 2)
|
||
{
|
||
richTextBox1.Text = "";
|
||
}
|
||
else if (flag == 3)
|
||
{
|
||
richTextBox1.Text = "";
|
||
}
|
||
else if (flag == 4)
|
||
{
|
||
richTextBox1.Text = "";
|
||
}
|
||
else if (flag == 5)
|
||
{
|
||
richTextBox1.Text = "";
|
||
}
|
||
else if (flag == 6)
|
||
{
|
||
richTextBox1.Text = "";
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Ïîæàëóéñòà, âûáåðèòå çàäàíèå");
|
||
}
|
||
}
|
||
|
||
private void button10_Click(object sender, EventArgs e)
|
||
{
|
||
if (flag == 1)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void Button2_Click(object sender, EventArgs e)
|
||
{
|
||
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
|
||
int Min = int.MaxValue, minIndex = -1, Max = int.MinValue, maxIndex = -1;
|
||
|
||
for (int i = 0; i < array.Length; i++)
|
||
{
|
||
if (array[i] > Max && array[i] < 0)
|
||
{
|
||
Max = array[i];
|
||
maxIndex = i;
|
||
}
|
||
if (array[i] < Min && array[i] > 0)
|
||
{
|
||
Min = array[i];
|
||
minIndex = i;
|
||
}
|
||
}
|
||
int begin = Math.Min(minIndex, maxIndex) + 1, end = Math.Max(minIndex, maxIndex) - 1;
|
||
for (; begin < end; begin++, end--)
|
||
{
|
||
int tmp = array[begin];
|
||
array[begin] = array[end];
|
||
array[end] = tmp;
|
||
}
|
||
richTextBox1.Text = string.Join(", ", array);
|
||
}
|
||
|
||
private void Button3_Click(object sender, EventArgs e)
|
||
{
|
||
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
|
||
|
||
for (int i = 0; i < array.Length; i++)
|
||
{
|
||
if (array[i] < 0)
|
||
{
|
||
Array.Resize(ref array, array.Length + 1); // Óâåëè÷èâàåì ðàçìåð ìàññèâà íà 1
|
||
for (int j = array.Length - 1; j > i + 1; j--) // Ñäâèãàåì âñå ýëåìåíòû ïîñëå òåêóùåãî íà 1 ïîçèöèþ âïðàâî
|
||
{
|
||
array[j] = array[j - 1];
|
||
}
|
||
array[i + 1] = -1; // Âñòàâëÿåì ÷èñëî 2 ïîñëå òåêóùåãî ýëåìåíòà
|
||
i++; // Ïðîïóñêàåì ñëåäóþùóþ èòåðàöèþ öèêëà, ÷òîáû íå îáðàáàòûâàòü âñòàâëåííîå ÷èñëî 2
|
||
}
|
||
|
||
}
|
||
richTextBox1.Text = string.Join(", ", array);
|
||
}
|
||
|
||
private void Button4_Click(object sender, EventArgs e)
|
||
{
|
||
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
|
||
|
||
for (int i = 0; i < array.Length; i++)
|
||
{
|
||
if (array[i] < 0)
|
||
{
|
||
// Óâåëè÷èâàåì ðàçìåð ìàññèâà íà 1
|
||
for (int j = i; j < array.Length - 1; j++) // Ñäâèãàåì âñå ýëåìåíòû ïîñëå òåêóùåãî íà 1 ïîçèöèþ âïðàâî
|
||
{
|
||
array[j] = array[j + 1];
|
||
}
|
||
|
||
Array.Resize(ref array, array.Length - 1);
|
||
i--;
|
||
}
|
||
|
||
}
|
||
richTextBox1.Text = string.Join(", ", array);
|
||
}
|
||
|
||
private void Button5_Click(object sender, EventArgs e)
|
||
{
|
||
/* int m = arrayTextBox.Lines.Length-1;
|
||
int n = arrayTextBox.Lines[0].Split(' ').Length-1;
|
||
int[,] array = new int[m, n];
|
||
for (int i = 0; i < m; i++)
|
||
{
|
||
string[] s = arrayTextBox.Lines[i].Split(' ');
|
||
for (int j = 0; j < n; j++)
|
||
{
|
||
array[i, j] = Int32.Parse(s[j]);
|
||
}
|
||
}
|
||
richTextBox1.Text = string.Join(", ", array);*/
|
||
|
||
int[,] array2 = array2D;
|
||
|
||
}
|
||
}
|
||
} |