#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
 
const int n = 8;
int p[n] ;
 
void umisti (int k) /* k .. cislo sloupce */
{
    for (int i = 0; i < n; i++)
    {
        bool ok = true;
 
        for (int d = 1; d <= k; d++)
        {
            if (p[k-d] == i || p[k-d] == i-d || p[k-d] == i+d)
            {
                ok = false;
            }
        }
 
        if (ok)
        {
            p[k] = i;
            if (k < n - 1)
                umisti (k + 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;
 
    umisti (0);
 
    // for (int k = 0; k < n; k++)  cout << p[k] << " ";
    // cout << endl;
 
    cout << "Konec programu" << endl;
    system ("pause");
    return 0;
}
 
data_2018_ut.txt · Last modified: 2018/03/27 11: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