I'm going to make an N-queen with a stack. However, There's a problem with the chords. The console window says "return value 3221225477" I searched it was a scanf problem, but I'm not It hasn't been long since I learned coding, so the code is inefficient and complicated. I'm so sorry. Please give me a kind explanation.
#include <stdio.h>
#include <stack>
#include <math.h>
int n, col[11], k = 1;
void output(){
for(int i = 1; i<=n; i++)
printf("(%d, %d)",i,col[i]);
printf("\n");
}
int main()
{
std::stack <int> S;
int check, flag = 1, i = 1;
scanf(" %d", &n);
for(int j = 1; j <= n;j++)
S.push(n-j+1);
while(!S.empty())
{
while(S.top() == 0)
{
S.pop();
printf("%d",k);
k--;
}
check = 0;
col[k] = S.top();
if(k == n)
output();
if(!S.empty())
S.pop();
for(int j = 1; j <= n && k < n; j++)
{
flag = 1;
i = 1;
while(i < k+1){
if((abs(i-(k+1)) == abs(col[i]-j)) || (col[i] == j))
flag = 0;
i++;
}
if(flag == 1)
{
if(check == 0)
{
S.push(0);
k++;
check = 1;
}
S.push(j);
}
}
}
}