Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ChessQueens
- {
- class ChessQueens
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int distance = int.Parse(Console.ReadLine());
- string[,] board = new string[n, n];
- char initial = 'a';
- List<string> collected = new List<string>();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- board[i, j] = Convert.ToString(initial) + Convert.ToString(j + 1);
- }
- initial++;
- }
- if (distance >= n - 1)
- {
- Console.WriteLine("No valid positions");
- return;
- }
- else
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j+distance+1 < n; j++)
- {
- string[] temp = new string[2] { board[i, j], board[i, j + distance + 1] };
- string one = temp[0] + " - " + temp[1];
- string two = temp[1] + " - " + temp[0];
- collected.Add(one);
- collected.Add(two);
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j + distance + 1 < n; j++)
- {
- string[] temp = new string[2] { board[j, i], board[j + distance + 1, i]};
- string one = temp[0] + " - " + temp[1];
- string two = temp[1] + " - " + temp[0];
- collected.Add(one);
- collected.Add(two);
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j + distance + 1 < n && i+distance+1 < n; j++)
- {
- string[] temp = new string[2] { board[i, j], board[i + distance + 1, j + distance + 1] };
- string one = temp[0] + " - " + temp[1];
- string two = temp[1] + " - " + temp[0];
- collected.Add(one);
- collected.Add(two);
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = n - 1; j - distance - 1 >= 0 && i+distance+1 < n; j--)
- {
- string[] temp = new string[2] { board[i, j], board[i+distance+1, j-distance-1] };
- string one = temp[0] + " - " + temp[1];
- string two = temp[1] + " - " + temp[0];
- collected.Add(one);
- collected.Add(two);
- }
- }
- }
- List<string> noDupes = collected.Distinct().ToList();
- noDupes.Sort();
- foreach (var item in noDupes)
- {
- Console.WriteLine(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement