zh_stoqnov

ChessQueens

Nov 3rd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 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 ChessQueens
  8. {
  9. class ChessQueens
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. int d = int.Parse(Console.ReadLine());
  15. int diff = d + 1;
  16. char[] letters = new char[n];
  17. int count = 0;
  18.  
  19. for(int i = 0; i < n; i++)
  20. {
  21. letters[i] = (char)('a' + i);
  22. }
  23.  
  24. for (int x1 = 0; x1 < n; x1++)
  25. {
  26. for(int y1 = 0; y1 < n; y1++)
  27. {
  28. for(int x2 = 0; x2 < n; x2++)
  29. {
  30. for(int y2 = 0; y2 < n; y2++)
  31. {
  32. bool xMeet = x1 == x2 && Math.Abs(y1 - y2) == diff;
  33. bool yMeet = y1 == y2 && Math.Abs(x1 - x2) == diff;
  34. bool diagonalMeet = Math.Abs(x1 - x2) == diff && Math.Abs(y1 - y2) == diff;
  35.  
  36. if(xMeet || yMeet || diagonalMeet)
  37. {
  38. Console.WriteLine("{0}{1} - {2}{3}", letters[x1], y1 + 1, letters[x2], y2 + 1);
  39. count++;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. if(count == 0)
  46. {
  47. Console.WriteLine("No valid positions");
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment