-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
36 lines (33 loc) · 851 Bytes
/
Copy pathc.cpp
File metadata and controls
36 lines (33 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
char a[8][8] = {};
for(int y=0; y<8; y++){
for(int x=0; x<8; x++){
cin >> a[y][x];
}
}
vector<int> q = {0, 1, 2, 3, 4, 5, 6, 7};
do{
bool valid = true;
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
if(a[i][j]=='Q' && q[i]!=j) valid = false;
if(i!=j && abs(i-j)==abs(q[i]-q[j])) valid = false;
}
}
if(valid){
for(int y=0; y<8; y++){
for(int x=0; x<8; x++){
cout << (q[y]==x? 'Q' : '.');
}
cout << endl;
}
return 0;
}
}
while(next_permutation(q.begin(), q.end()));
cout << "No Answer" << endl;
}