Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Laba
- {
- class Program
- {
- public static System.Random rnd = new System.Random();
- public static char[] text = new char[100]; // первый массив, в который заносим буквы и цифры
- public static char[] text2; // второй массив, в который заносим только ходы конем
- static void Main(string[] args)
- {
- for (int i = 0; i < 100; i++)
- {
- if (i % 2 == 0) // если остаток деления на 2 = 0, то заносим любую цифру от 1 до 8
- {
- text[i] = char.Parse(rnd.Next(1, 9).ToString());
- //Console.WriteLine(text[i]);
- }
- else // иначе заносим любую букву от A до H
- {
- text[i] = Convert.ToChar(Convert.ToInt32(rnd.Next(65,73)));
- //Console.WriteLine(text[i]);
- }
- }
- for (int i = 0; i < 100; )
- {
- // если цифра ряда меняется +2 или -2, буква меняется +1 или -1 и наоборот, то это ход конем
- 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)))
- {
- for (int j = 1; j < 5; j++)
- {
- text2[i] = text[i+j- 1]; // и заносим во второй массив
- Console.WriteLine(text2[i]); // сразу выводим
- }
- i = i + 4; // как занесли - перепрыгиваем на 4 элемента
- }
- else // иначе, выводим, что записей с ходом коня нет
- {
- i = i + 4; // тоже перепрыгиваем
- Console.WriteLine("Записей с ходом коня нет!");
- }
- }
- for (int i = 0; i < text.Length; i++)
- {
- Array.Sort(text, 0, 100); // сортируем по возрастающей
- Console.WriteLine(text[i]); // выводим первый массив
- }
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment