Guest User

Untitled

a guest
Jan 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Laba
  7. {
  8.     class Program
  9.     {
  10.         public static System.Random rnd = new System.Random();
  11.         public static char[] text = new char[100]; // первый массив, в который заносим буквы и цифры
  12.         public static char[] text2; // второй массив, в который заносим только ходы конем
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             for (int i = 0; i < 100; i++)
  17.             {
  18.                 if (i % 2 == 0) // если остаток деления на 2 = 0, то заносим любую цифру от 1 до 8
  19.                 {
  20.                     text[i] = char.Parse(rnd.Next(1, 9).ToString());
  21.                     //Console.WriteLine(text[i]);
  22.                 }
  23.                 else // иначе заносим любую букву от A до H
  24.                 {
  25.                     text[i] = Convert.ToChar(Convert.ToInt32(rnd.Next(65,73)));
  26.                     //Console.WriteLine(text[i]);
  27.                 }
  28.             }
  29.  
  30.             for (int i = 0; i < 100; )
  31.             {
  32.                 // если цифра ряда меняется +2 или -2, буква меняется +1 или -1 и наоборот, то это ход конем
  33.                 if (((text[i + 3] == text[i] + 2 || text[i + 3] == text[i] - 2) && (text[i + 4] == text[i + 2] + 1 || text[i + 4] == text[i + 2] - 1)) || ((text[i + 3] == text[i] + 1 || text[i + 3] == text[i] - 1) && (text[i + 4] == text[i + 2] + 2 || text[i + 4] == text[i + 2] - 2)))
  34.                 {
  35.                     for (int j = 1; j < 5; j++)
  36.                     {
  37.                         text2[i] = text[i+j- 1]; // и заносим во второй массив
  38.                         Console.WriteLine(text2[i]); // сразу выводим
  39.                     }
  40.                     i = i + 4; // как занесли - перепрыгиваем на 4 элемента
  41.                 }
  42.                 else // иначе, выводим, что записей с ходом коня нет
  43.                 {
  44.                     i = i + 4; // тоже перепрыгиваем
  45.                     Console.WriteLine("Записей с ходом коня нет!");
  46.                 }
  47.                
  48.             }
  49.             for (int i = 0; i < text.Length; i++)
  50.             {
  51.                 Array.Sort(text, 0, 100); // сортируем по возрастающей
  52.  
  53.                 Console.WriteLine(text[i]); // выводим первый массив
  54.             }
  55.             Console.ReadLine();
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment