Praktika_Pibd-14/Praktika/Form1.cs

234 lines
7.9 KiB
C#
Raw Normal View History

2024-06-25 22:22:18 +04:00
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.");
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.");
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));
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
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($"<22><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {seriesStartIndex} <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> {seriesLength}");
flag = 1;
}
private void Button9_Click(object sender, EventArgs e)
{
if (flag == 1)
{
richTextBox1.Text = "<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> N." +
"<22><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>." +
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" +
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>" +
"<22><><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" +
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>.";
}
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
}
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); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1
for (int j = array.Length - 1; j > i + 1; j--) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
array[j] = array[j - 1];
}
array[i + 1] = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 2 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
i++; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 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)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1
for (int j = i; j < array.Length - 1; j++) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
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;
}
}
}