Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int dem1 = 0;
- int hang[8], cot[8], cheo1[15], cheo2[15];
- int nuoc[2][8];
- int Try(int i, int j)
- {
- if (hang[i] != 1 && cot[j] != 1 && cheo1[i + j] != 1 && cheo2[i - j + 7] != 1) return 1;
- return 0;
- }
- void DatQuan(int i, int j, int x)
- {
- hang[i] = x;
- cot[j] = x;
- cheo1[i + j] = x;
- cheo2[i - j + 7] = x;
- }
- void Tim(int i, int k, int dem)
- {
- if (dem == 8)
- {
- for (int h = 0; h < 8; h++)
- cout << nuoc[1][h] << '\t' << nuoc[0][h] << endl;
- getch();
- system("cls");
- return;
- }
- for (int j = 0; j < 8; j++)
- {
- if (Try(i, j) == 1)
- {
- nuoc[0][i] = i;
- nuoc[1][i] = j;
- if (i == 8)
- {
- return;
- }
- DatQuan(i, j, 1);
- Tim(i + 1, j, dem + 1);
- }
- else
- continue;
- DatQuan(i, j, 0);
- }
- }
- void main()
- {
- Tim(0, 0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement