Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_4___Chess_Queens
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int[,] board = new int[n, n];
  15.             int d = int.Parse(Console.ReadLine());
  16.             int count = 0;
  17.             bool up = false;
  18.             bool down = false;
  19.             bool left = false;
  20.             bool right = false;
  21.  
  22.             for (int i = 0; i < n; i++)
  23.             {
  24.                 for (int j = 0; j < n; j++)
  25.                 {
  26.                     if (j + d + 1 < n)
  27.                     {
  28.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i), j + d + 2);
  29.                         count++;
  30.                         right = true;
  31.                     }
  32.                     if (j - (d + 1) >= 0)
  33.                     {
  34.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i), j - (d + 1) + 1);
  35.                         count++;
  36.                         left = true;
  37.                     }
  38.                     if (i+d+1<n)
  39.                     {
  40.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i + d + 1), j+1 );
  41.                         count++;
  42.                         down = true;
  43.                     }
  44.                    
  45.                     if (i -( d + 1)>= 0)
  46.                     {
  47.                         Console.WriteLine("{0}{1} - {2}{3}",( char) ('a' + i), j+1, (char)('a' + i-( d + 1)), j+1);
  48.                         count++;
  49.                         up = true;
  50.                     }
  51.                     if (right && down)
  52.                     {
  53.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i + d + 1), j + d + 1 + 1);
  54.                         count++;
  55.                     }
  56.                     if (left && down)
  57.                     {
  58.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j + 1, (char)('a' + i + d + 1), j - (d + 1) + 1);
  59.                         count++;
  60.                     }
  61.  
  62.                     if (left&&up)
  63.                     {
  64.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i - (d + 1)), j - (d - 1) + 1);
  65.                         count++;
  66.                     }
  67.                     if (right&&up)
  68.                     {
  69.                         Console.WriteLine("{0}{1} - {2}{3}", (char)('a' + i), j+1, (char)('a' + i - (d + 1)), j + d + 1 + 1);
  70.                         count++;
  71.                     }
  72.                    
  73.                    
  74.                      up = false;
  75.                      down = false;
  76.                      left = false;
  77.                      right = false;
  78.                 }
  79.  
  80.             }
  81.             if (count==0)
  82.             {
  83.                 Console.WriteLine("No valid position");
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement