#include using namespace std; int n = 8; int a[9]; int dem = 1; bool Check(int i, int j) { for (int k = 1; k < i; k++) if (a[k] == j || abs(k - i) == abs(a[k] - j)) return false; return true; } void Show() { cout << "Cach " << dem++ << " co cac buoc dat la: " << endl; for (int i = 1; i <= n; i++) { cout << setw(2) << "(" << i << "," << a[i] << ")"; } cout << endl; } void Try(int i) { int j = 1; do { if (Check(i, j)) { a[i] = j; if (i == n) Show(); Try(i + 1); } j++; } while (j <= n); } int main() { Try(1); return 0; }