#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
 
const int n = 8;
 
int p[n];
 
void place (int i)
{
    for (int k = 0; k < n; k++)
    {
        bool ok = true;
        for (int d = 1; d <= i; d++)
        {
            if (p[i - d] == k || p[i - d] == k - d || p[i - d] == k + d)
                ok = false;
        }
        if (ok)
        {
            p[i] = k;
            if (i != n - 1)
                place (i + 1);
            else
            {
                for (int l = 0; l < n; l++)
                    cout << p[l] << " ";
                cout << endl;
            }
        }
    }
}
 
int main ()
{
    for (int k = 0; k < n; k++) p[k] = -1;
 
    place (0);
 
    cout << "Konec programu" << endl;
    system ("pause");
    return 0;
}
 
data_2018_st.txt · Last modified: 2018/03/28 17:13 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki