forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8queens.cpp
47 lines (41 loc) · 960 Bytes
/
8queens.cpp
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
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
using namespace std;
int main() {
char ch;
vector<bool> a;
vector<bool> b;
vector<bool> c;
vector<bool> d;
a.resize(15, false);
b.resize(15, false);
c.resize(8, false);
d.resize(8, false);
int queens = 0;
for(int i = 0; i < 8; i++) {
for(int j = 0; j < 8; j++) {
cin >> ch;
while(ch != '*' && ch != '.') {
cin >> ch;
}
if(ch == '*') {
queens++;
if(a[j-i+7] || b[i+j] || c[i] || d[j]) {
cout << "invalid" << endl;
return 0;
}
a[j - i + 7] = true;
b[i + j] = true;
c[i] = true;
d[j] = true;
}
}
}
if(queens == 8) {
cout << "valid" << endl;
}
else {
cout << "invalid" << endl;
}
return 0;
}