Public feed
#376749
#include<iostream>/* Knight Tour */ const int size = 8; void initialization(); void print(); void Knight ( int times, int row, int col ); bool K[size][size]; bool check( int row, int col); //int move_col[] = {-1, -2, -2, -1, +1, +2, +2, +1}; //int move_row[] = {+2, +1, -1, -2, -2, -1, +1, +2}; int move_col[] = {-2, -1, +1, +2, +2, +1, -1, -2}; int move_row[] = {+1, +2, +2, +1, -1, -2, -2, -1}; int row, col, index, next_row, next_col; int times;void initialization(){ index =0; times = 0; row = 0; col = 0; for ( int i=0; i < size; i++) { for ( int j=0; j < size; j++) { K[i][j] = false; } } K[row][col] = true;}bool check ( int row, int col ){ if ( row > 7 || row < 0 || col > 7 || col < 0 || K[row][col] == true ) return false; else return true;}void print (){ index++; cout << " Let's go Knight ^^" << endl; cout << " The : "<< index << "th"<< endl; for ( int k = 0; k < size; k++ ) { for ( int m = 0; m < size; m++ ) { if ( K[k][m] == true ) { cout << " K " ; } else cout << " * "; } cout << endl; }}void Knight ( int times, int row, int col){ K[row][col] = true; if ( times >= 63 ) { print(); cin.get(); } else { for ( int i = 0; i < 8; i++ ) { next_col = col + move_col[i]; next_row = row + move_row[i]; if (check( next_row,next_col )) { Knight (times+1, next_row, next_col); } } } K[row][col] = false;} void main(){ initialization(); Knight (0,0,0);int x;cin >> x;}