Advertisement
RenSafaray

Untitled

Apr 26th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using System.IO;
  5.  
  6. namespace _3
  7. {
  8.     public partial class Form1 : Form
  9.     {
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.         List<string> text = new List<string>();
  15.         string st;
  16.         private void button1_Click_1(object sender, EventArgs e)
  17.         {
  18.             StreamReader sr = new StreamReader(@"C:\Users\ilyae\OneDrive\Рабочий стол\test.txt");
  19.             while (!sr.EndOfStream)
  20.             {
  21.                 st = sr.ReadLine();
  22.                 listBox1.Items.Add(st);
  23.                 text.Add(st);
  24.             }
  25.             sr.Close();
  26.             Controls.Remove(button1);
  27.         }
  28.         private void button2_Click(object sender, EventArgs e)
  29.         {
  30.             Random rn = new Random();
  31.             for (int i = 0; i < listBox1.Items.Count; i++)
  32.             {
  33.                 for (int j = i + 1; j < listBox1.Items.Count - 1; rn.Next(0, listBox1.Items.Count + 1))
  34.                 {
  35.                     st = listBox1.Items[i].ToString();
  36.                     listBox1.Items[i] = listBox1.Items[j];
  37.                     listBox1.Items[j] = st;
  38.                     break;
  39.                 }
  40.             }
  41.         }
  42.         int numb;
  43.         private void button4_Click(object sender, EventArgs e)
  44.         {
  45.             Single x;
  46.             if (Single.TryParse(textBox1.Text, out x) == false) MessageBox.Show("Введите целое число.");
  47.             else
  48.             {
  49.                 numb = int.Parse(textBox1.Text);
  50.                 if (numb > listBox1.Items.Count || numb <= 0 || numb == 1) MessageBox.Show("Введено неверное число.");
  51.                 else
  52.                 {
  53.                     numb -= 1;
  54.                     for (int i = numb - 1; ; i++)
  55.                     {
  56.                         for (int j = numb; ; j++)
  57.                         {
  58.                             st = listBox1.Items[i].ToString();
  59.                             listBox1.Items[i] = listBox1.Items[j];
  60.                             listBox1.Items[j] = st;
  61.                             break;
  62.                         }
  63.                         break;
  64.                     }
  65.                 }
  66.             }
  67.             textBox1.Clear();
  68.         }
  69.  
  70.         private void button3_Click(object sender, EventArgs e)
  71.         {
  72.             Single x;
  73.             if (Single.TryParse(textBox1.Text, out x) == false) MessageBox.Show("Введите целое число.");
  74.             else
  75.             {
  76.                 numb = int.Parse(textBox1.Text);
  77.                 if (numb >= listBox1.Items.Count || numb <= 0) MessageBox.Show("Введено неверное число.");
  78.                 else
  79.                 {
  80.                     numb -= 1;
  81.                     for (int i = numb + 1; ; i++)
  82.                     {
  83.                         for (int j = numb; ; j++)
  84.                         {
  85.                             st = listBox1.Items[i].ToString();
  86.                             listBox1.Items[i] = listBox1.Items[j];
  87.                             listBox1.Items[j] = st;
  88.                             break;
  89.                         }
  90.                         break;
  91.                     }
  92.                 }
  93.             }
  94.             textBox1.Clear();
  95.         }
  96.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  97.         {
  98.  
  99.         }
  100.         int k = 0;
  101.         private void button5_Click_1(object sender, EventArgs e)
  102.         {
  103.             for (int g = 0; g < text.Count; g++)
  104.             {
  105.                 st = listBox1.Items[g].ToString();
  106.                 if (text[g] != st)
  107.                 {
  108.                     MessageBox.Show("Расстановки строк не равны.");
  109.                     break;
  110.                 }
  111.                 else k++;
  112.             }
  113.             if (k == text.Count) MessageBox.Show("Расстановки строк равны.");
  114.         }
  115.     }
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement