κ°μ λκ°μ μ μλ€λ©΄ xμ’νμ yμ’νμ ν©μ΄λ μ°¨κ° κ°λ€λ μ¬μ€μ μ΄μ©ν΄μ νλ‘κ·Έλλ°νμ΅λλ€.
μ’ μ΄κ±°μ§λ‘ μμ€ μ½λ ν¬κΈ°λ₯Ό μ€μμ΅λλ€. -_-a
μ’ μ΄κ±°μ§λ‘ μμ€ μ½λ ν¬κΈ°λ₯Ό μ€μμ΅λλ€. -_-a
λλ²μ§Έ νλ‘κ·Έλ¨μ ... μ΄μνκ² μ»΄νμΌμ΄ μλλκ΅°μ.. μκ³ λ³΄λ #include <stdafx.h> μ μ λ£μ΄μ (VC6.0) λν¨-_-a
νλμ ν΄λ§ ꡬνλ νλ‘κ·Έλ¨ ¶
~cpp
#include <stdio.h>
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 <stdio.h>
#include <conio.h>
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;
}










