Created
April 11, 2010 00:56
-
-
Save dchiji/362411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int count = 0; | |
int put_queen(int lines[], int size, int n) | |
{ | |
int i; | |
int j; | |
if(n == size) { | |
int k; | |
int l; | |
for(k = 0; k < size; k++) { | |
for(l = 0; l < lines[k]; l++) printf(" "); | |
printf("*\n"); | |
} | |
printf("\n\n\n"); | |
count++; | |
return 0; | |
} | |
for(i = 0; i < 8; i++) { | |
lines[n] = i; | |
for(j = 0; j < n; j++) { | |
if(lines[j] == i || lines[j] - (n - j) == i || lines[j] + (n - j) == i) goto CONTINUE; | |
} | |
put_queen(lines, size, n + 1); | |
CONTINUE: | |
continue; | |
} | |
} | |
int main() | |
{ | |
int lines[8]; | |
put_queen(lines, 8, 0); | |
printf("%d\n", count); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define N 8 | |
int count = 0; | |
int put_queen(int lines[], int size, int n) | |
{ | |
int i; | |
int j; | |
if(n == size) { | |
int k; | |
int l; | |
for(k = 0; k < size; k++) { | |
for(l = 0; l < lines[k]; l++) printf(" "); | |
printf("*\n"); | |
} | |
printf("\n\n\n"); | |
count++; | |
return 0; | |
} | |
for(i = 0; i < N; i++) { | |
lines[n] = i; | |
for(j = 0; j < n; j++) { | |
if(lines[j] == i || lines[j] - (n - j) == i || lines[j] + (n - j) == i) goto CONTINUE; | |
} | |
put_queen(lines, size, n + 1); | |
CONTINUE: | |
continue; | |
} | |
} | |
int main() | |
{ | |
int lines[N]; | |
put_queen(lines, N, 0); | |
printf("%d\n", count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment