#include "stdafx.h" #include #include using namespace std; const int n = 8; int p[n][n]; int zx[n][n]; int zy[n][n]; void skok (int x, int y, int d, int x0, int y0) { if (x >= 0 && x < n && y >= 0 && y < n) { if (p[x][y] == -1 || p[x][y]>d) { p[x][y] = d; zx[x][y] = x0; zy[x][y] = y0; skok (x + 2, y + 1, d + 1, x, y); skok (x + 2, y - 1, d + 1, x, y); skok (x + 1, y + 2, d + 1, x, y); skok (x + 1, y - 2, d + 1, x, y); skok (x - 2, y + 1, d + 1, x, y); skok (x - 2, y - 1, d + 1, x, y); skok (x - 1, y + 2, d + 1, x, y); skok (x - 1, y - 2, d + 1, x, y); } } } void print (int x, int y) { if (x != -1) { print (zx[x][y], zy[x][y]); cout << x << "," << y << endl; } } int main () { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { p[i][j] = -1; zx[i][j] = -1; zy[i][j] = -1; } int x = 0; int y = 0; skok (x, y, 0, -1, -1); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == -1) cout << ". "; else cout << p[i][j] << " "; } cout << endl; } cout << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << "(" << zx[i][j] << "," << zy[i][j] << ")" << " " ; } cout << endl; } print (7, 7); /* x = 7; y = 7; while (x != -1) { cout << x << "," << y << endl; int x1 = zx[x][y]; int y1 = zy[x][y]; x = x1; y = y1; } */ cout << "Konec programu" << endl; system ("pause"); return 0; }