Advertisement
Guest User

Chess Queens

a guest
Aug 27th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. using System;
  2.  
  3. class ChessQueens
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int d = int.Parse(Console.ReadLine());
  9.         int matchings = 0;
  10.         char a = 'a';
  11.         char end = (char)(a + n);
  12.         for (char i = 'a'; i < end; i++)
  13.         {
  14.             for (int j = 1; j <= n; j++)
  15.             {
  16.                 for (char k = 'a'; k < end; k++)
  17.                 {
  18.                     for (int g = 1; g <= n; g++)
  19.                     {
  20.                         //for (int m = 1; m < n; m++)
  21.                         {
  22.                             if ((k == i + d + 1) && (g == j + d + 1))
  23.                             {
  24.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  25.                                 matchings++;
  26.                             }
  27.                             else if (i == k && g == j - d - 1)
  28.                             {
  29.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  30.                                 matchings++;
  31.                             }
  32.                             else if (j == g && k == i - 1 - d)
  33.                             {
  34.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  35.                                 matchings++;
  36.                             }
  37.                             else if (k == i - d - 1 && j == g - d - 1)
  38.                             {
  39.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  40.                                 matchings++;
  41.                             }
  42.                             else if (k == i - d - 1 && g == j - d - 1)
  43.                             {
  44.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  45.                                 matchings++;
  46.                             }
  47.                             else if (i == k - 1 - d && j == g - d - 1)
  48.                             {
  49.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  50.                                 matchings++;
  51.                             }
  52.                             else if (i == k - d - 1 && g == j - d - 1)
  53.                             {
  54.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  55.                                 matchings++;
  56.                             }
  57.                             else if (k == i + d + 1 && g == j)
  58.                             {
  59.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  60.                                 matchings++;
  61.                             }
  62.                             else if (g == j + d + 1 && i == k)
  63.                             {
  64.                                 Console.WriteLine("{0}{1} - {2}{3}", i, j, k, g);
  65.                                 matchings++;
  66.                             }
  67.                             else
  68.                             {
  69.                                 continue;
  70.                             }
  71.                         }
  72.  
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.         if (matchings == 0)
  78.         {
  79.             Console.WriteLine("No valid positions");
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement