Advertisement
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;
- using System.Threading.Tasks;
- namespace Problem_4___Chess_Queens
- {
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[,] board = new int[n, n];
- int d = int.Parse(Console.ReadLine());
- int count = 0;
- bool up = false;
- bool down = false;
- bool left = false;
- bool right = false;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (j + d + 1 < n)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i), j + d + 2);
- count++;
- right = true;
- }
- if (j - (d + 1) >= 0)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i), j - (d + 1) + 1);
- count++;
- left = true;
- }
- if (i+d+1<n)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i + d + 1), j+1 );
- count++;
- down = true;
- }
- if (i -( d + 1)>= 0)
- {
- Console.WriteLine("{0}{1} - {2}{3}",( char) ('a' + i), j+1, (char)('a' + i-( d + 1)), j+1);
- count++;
- up = true;
- }
- if (right && down)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i + d + 1), j + d + 1 + 1);
- count++;
- }
- if (left && down)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i + d + 1), j - (d + 1) + 1);
- count++;
- }
- if (left&&up)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i - (d + 1)), j - (d - 1) + 1);
- count++;
- }
- if (right&&up)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i - (d + 1)), j + d + 1 + 1);
- count++;
- }
- up = false;
- down = false;
- left = false;
- right = false;
- }
- }
- if (count==0)
- {
- Console.WriteLine("No valid position");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement