Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Chess Queens
- //We are given a chess board of size N * N. The only figures we have on the
- //chess board are two queens. The queen in chess can move in horizontal, vertical and diagonal directions. We are also given a //number D which represents the distance between the two queens. The distance is measured by D squares away. All positions on the //chessboard are represented with numbers and letters (a1, a2β¦ a8, b1-b8, c1-c8, β¦, h1-h8). Example: if N=16, the numbers on the //board will be represented with integers (1-16) and letters (a-o). Your task is to find all couples of queens where the queens //stay either on the same vertical, horizontal or diagonal, at distance D. See the diagram aside to understand your task better. //The green queens meet the condition of 2 blocks away but the red queens arenβt.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int d = int.Parse(Console.ReadLine());
- int lastNum = '`' + n;
- char lastLetter = (char)lastNum;
- int count = 0;
- for (char firstLetter = 'a'; firstLetter <= lastLetter; firstLetter++)
- {
- for (int firstNum = 1; firstNum <= n; firstNum++)
- {
- for (int secondLetter = 'a'; secondLetter <= lastLetter; secondLetter++ )
- {
- for (int secondNum = 1; secondNum <= n; secondNum++)
- {
- if (firstLetter == secondLetter && secondNum - firstNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (firstNum == secondNum && secondLetter - firstLetter == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (firstLetter == secondLetter && firstNum - secondNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (firstNum == secondNum && firstLetter - secondLetter == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (firstLetter - secondLetter == d + 1 && firstNum - secondNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (secondLetter - firstLetter == d + 1 && secondNum - firstNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (firstLetter - secondLetter == d + 1 && secondNum - firstNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- if (secondLetter - firstLetter == d + 1 && firstNum - secondNum == d + 1)
- {
- Console.WriteLine("{0}{1} - {2}{3}", (char)firstLetter, firstNum, (char)secondLetter, secondNum);
- count++;
- }
- }
- }
- }
- }
- if (count == 0)
- {
- Console.WriteLine("No valid positions");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement