The idea behind this problem is to represent a configuration of 8 queens with a one-dimensional array. So a[0] represents the first row, a[1] the second row etc. and a[row]=column
position, where column position represents the "row position" of the queen.
Is there anything I can improve?
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int a[7];
int m, b, i=0, x, y, k=0, c,u;
for(u=0; u<8; u++){
cin>>a[u];
}
for(m=0; m<7; m++){
for(b=m+1; b<=7; b++){
if(a[m]==a[b]) i++;
}
}
for(x=0; x<7; x++){
c=0;
for(y=x+1; y<=7; y++){
c++;
if(abs(a[x]-a[y])==c) k++;
}
}
if(i==0 && k==0) cout<<"valid";
else cout<<"invalid";
}