같은 대각선에 있다면 x좌표와 y좌표의 합이나 차가 같다는 사실을 이용해서 프로그래밍했습니다. 좀 어거지로 소스 코드 크기를 줄였습니다. -_-a 두번째 프로그램은 ... 이상하게 컴파일이 안되더군요.. 알고보니 #include 을 안 넣어서 (VC6.0) 낭패-_-a == 하나의 해만 구하는 프로그램 == {{{~cpp #include int t[8],check(int),is_finished=0; void make(int); int check(int pos) { int i,j; for (i=0;i<=pos;i++) for (j=0;j<=pos;j++) if ((i!=j)&&(t[i]==t[j]||t[i]+i==t[j]+j||t[i]-i==t[j]-j)) return 0; return 1; } void make(int pos) { int i; if (is_finished==0) if (pos<8) {for (i=0;i<8;i++) {t[pos]=i; if (check(pos)) make(pos+1);}} else {is_finished=1; // 하나의 해만 찾음 <- 이 부분이 없으면 여러가지 해 출력 for (i=0;i<8;i++) printf("%3d",t[i]);} } int main(int argc, char* argv[]) { make(0); return 0; } }}} == 모든 해를 구하는 프로그램 == {{{~cpp #include #include int t[8],check(int),count=0; void make(int); int check(int pos) { int i,j; for (i=0;i<=pos;i++) for (j=0;j<=pos;j++) if ((i!=j)&&(t[i]==t[j]||t[i]+i==t[j]+j||t[i]-i==t[j]-j)) return 0; return 1; } void make(int pos) { int i; if (pos<8) { for (i=0;i<8;i++) { t[pos]=i; if (check(pos)) make(pos+1); } } else { count++; printf("[%d] : ",count); for (i=0;i<8;i++) printf("%3d",t[i]); printf("\n"); } } int main(int argc, char* argv[]) { make(0); return 0; } }}}