Project2.exe (Delphi) ¶
์ํค๋ ๋จธ๋ฆฌํธ๋๊ณ ์ฒ์์ด๋ผ.. -_-;; ์ ๋๋ก ์ฐ๊ณ ์๋๊ฑด์ง ์ ๋ชจ๋ฅด๊ฒ ๊ตฐ์...
๋๋ถ๋ถ C, C++ ํน์ ์๋ฐ๋ก ์์ฑํ์
จ๋๋ฐ... ์ ๋ธํ์ด๋ก ํ์ต๋๋ค.
์ฌ์ค ์์ USES๋ ํผ, ๋ฒํผ, ํด๋ฆญ์ด๋ฒค๋ฑ์ ๋ณ ํ์์๋ ๋ถ๋ถ์ธ๋ฐ... ^^;;;
์ฌ์ค ์์ USES๋ ํผ, ๋ฒํผ, ํด๋ฆญ์ด๋ฒค๋ฑ์ ๋ณ ํ์์๋ ๋ถ๋ถ์ธ๋ฐ... ^^;;;
์ ์ข ๋ง์ด ํ์ ์ด๋ผ..T_T ์ ์์ค๋ ๋ณด์๋ฉด ๋๋ง ์ํ์ค ๊ฒ๋๋ค.
์ด๋ฐ์ ๋ฐฉํฅ์ ์๋ชป์ก์ ๋ง์ด ์ ๋จน์์ต๋๋ค. ๊ทธ๊ฒ๋์ ์๊ฐ๋ ๋ง์ด ์ก์๋จน์๊ณ ...
๋งต์ RECORD๋ก ์ ์ ํ ๋ค์ ํ ๋ผ์ธ์ ํ๋์ฉ ์ฌ์์ ์ฌ๋ ค ๋๊ณ ๊ทธ ๋๋ง๋ค ๊ณต๊ฒฉ ๊ฐ๋ฅ ํจ์ค๋ฅผ ๋ค ์ง์ฐ๋(?) ๋ฐฉ์์ผ๋ก ํ๋ คํ๋๋ฐ...
์ด๋ ๊ฒ ํ๋ฉด ์ธ๋ฐ์๋ ๋ฃจํ๋ฅผ ๋์ง ์์๋ ๋์ง๋ง ์ ๊ฒฝ์ธ๊ฒ ์ข ๋ง๋๊ตฐ์.. -_-;;
๋งต์ RECORD๋ก ์ ์ ํ ๋ค์ ํ ๋ผ์ธ์ ํ๋์ฉ ์ฌ์์ ์ฌ๋ ค ๋๊ณ ๊ทธ ๋๋ง๋ค ๊ณต๊ฒฉ ๊ฐ๋ฅ ํจ์ค๋ฅผ ๋ค ์ง์ฐ๋(?) ๋ฐฉ์์ผ๋ก ํ๋ คํ๋๋ฐ...
์ด๋ ๊ฒ ํ๋ฉด ์ธ๋ฐ์๋ ๋ฃจํ๋ฅผ ๋์ง ์์๋ ๋์ง๋ง ์ ๊ฒฝ์ธ๊ฒ ์ข ๋ง๋๊ตฐ์.. -_-;;
ํ์ฅ์ค์์ ๋ณผ ์ผ์ ๋ณด๋ฉด์ ์ข ์๊ฐํด๋ดค๋๋ฐ... ์ ๊ฐ ๋๋ฌด ์ด๋ ต๊ฒ ์งํํ๊ณ ์๋๋ฏ ์ถ๋๊ตฐ์.
๊ทธ๋์ ๋ฐฉ์์ ๋ฐ๊ฟจ์ต๋๋ค.
๊ณต๊ฒฉ ํจ์ค์ ๋ค์ด๊ฐ์ง ์๋ ์์น์ ์ฌ๋ ค ๋๋๊ฒ ์๋๋ผ ์ผ๋จ ์ฌ๋ ค ๋๊ณ ๊ณต๊ฒฉ๋ฐ์ ์ ์๋๊ฐ ์ฒดํฌํ๋ ๋ฐฉ์์ผ๋ก์.. ^^;;
๊ทธ๋์ ๋ฐฉ์์ ๋ฐ๊ฟจ์ต๋๋ค.
๊ณต๊ฒฉ ํจ์ค์ ๋ค์ด๊ฐ์ง ์๋ ์์น์ ์ฌ๋ ค ๋๋๊ฒ ์๋๋ผ ์ผ๋จ ์ฌ๋ ค ๋๊ณ ๊ณต๊ฒฉ๋ฐ์ ์ ์๋๊ฐ ์ฒดํฌํ๋ ๋ฐฉ์์ผ๋ก์.. ^^;;
์ ๊ฐ ์ฝ๋ฉ์ ํ ๋๋ง๋ค ๋๋ผ๋ ์ ์ ๋ฌธ์ ์ ์ธ๋ฐ..
ํญ์ ์ฝ๋ฉ์ด ๋๋๋ฉด ์ด๋ฐ์ ์ค๊ณํ ๊ฒ๊ณผ๋ ์ข ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ๋๊ฐ์๋๊ตฐ์.. -_-;;
์ด๋ฒ์๋ ์ ์ง ๋ชจ๋ฅด๊ฒ ์ข ์ด์คํ...
ํญ์ ์ฝ๋ฉ์ด ๋๋๋ฉด ์ด๋ฐ์ ์ค๊ณํ ๊ฒ๊ณผ๋ ์ข ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ๋๊ฐ์๋๊ตฐ์.. -_-;;
์ด๋ฒ์๋ ์ ์ง ๋ชจ๋ฅด๊ฒ ์ข ์ด์คํ...
์๊ฐ์ด ๋๋ฉด ์ฝ๋ ์ ๋ฆฌ๋ผ๋ ์ข ํ๋ ค๊ณ ํ๋๋ฐ...
๋ฒ์จ ์๊ฐ์ด.. -_-;;;; ์คํ๋ ์ด๊ฑธ๋ก ๋ค ๋ ๋ ค๋จน์๋ค์.
๋ฒ์จ ์๊ฐ์ด.. -_-;;;; ์คํ๋ ์ด๊ฑธ๋ก ๋ค ๋ ๋ ค๋จน์๋ค์.
์์ ์์ค๋ค์ ๋ดค๋๋ฐ ํ์คํ ์ ํ์ ์ด๋ผ๋๊ฒ ๋ค์ ํ๋ฒ ๋๊ปด์ง๋ค์.. T_T
๋ ์ธ์ ์ฏค์ด๋ฉด ๊ณ ์๊ฐ ๋๋ ค๋~~
๋ ์ธ์ ์ฏค์ด๋ฉด ๊ณ ์๊ฐ ๋๋ ค๋~~
์ผ... 2๋ฒ๋ฌธ์ ... ์ฒ์๋ถํฐ ๊ณํ์ด 2๋จผ๋ฌธ์ ์ ์๊ตฌ์ฌํญ์ ์ถฉ์กฑ์ํค๋ ๋ฐฉํฅ์ด์๊ธฐ ๋์..
์ ๋น์ฐํ ๊ทธ๋ ๊ฒ ํ์ค ์์๊ฑด๋ง.. ์ ๊ฐ ๋ญ๊ฐ ์๋ชปํ๊ณ ์์์๋ค์... -_-;;;
์ ๋น์ฐํ ๊ทธ๋ ๊ฒ ํ์ค ์์๊ฑด๋ง.. ์ ๊ฐ ๋ญ๊ฐ ์๋ชปํ๊ณ ์์์๋ค์... -_-;;;
์๋ฌด๋ฆฌ ๋ด๋ ์์ค๋ ๋ชจ๋ ํจ์ค๋ฅผ ๊ตฌํ๋๊ฑด๋ฐ... ์ด์ํ๋ค... ์๊ฐํ๋ค๊ฐ...
ํน์๋ ์ถ์ด์ ์ถ๋ ฅ๋ถ๋ถ์ ๋ฆฌ์ปค์๋ธ ์์ชฝ์ผ๋ก ์ฎ๊ฒจ๋์ผ๋.. ์ ๋์ค๋๊ตฐ์.. -_-;;
ํน์๋ ์ถ์ด์ ์ถ๋ ฅ๋ถ๋ถ์ ๋ฆฌ์ปค์๋ธ ์์ชฝ์ผ๋ก ์ฎ๊ฒจ๋์ผ๋.. ์ ๋์ค๋๊ตฐ์.. -_-;;
๊ทธ๋์ ๋...
๋ ๋ฉ๋ชจ ์ปดํฌ๋ํธ๋ ์ ์ฌ๋ ค ๋์๊ฑฐ์ง.. -_-;; ์ด์ฐจํผ showMessage๋ก ๋ณด์ฌ์ค๊ฑฐ์์ผ๋ฉด์....
๋ ๋ฉ๋ชจ ์ปดํฌ๋ํธ๋ ์ ์ฌ๋ ค ๋์๊ฑฐ์ง.. -_-;; ์ด์ฐจํผ showMessage๋ก ๋ณด์ฌ์ค๊ฑฐ์์ผ๋ฉด์....
~cpp
<script>
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
CBoardSize = 8;
type
TQueenPos = record
X: integer;
Y: integer;
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure SearchStart();
function getNextQueenPos(index, X, Y:integer):boolean;
function checkRule(X,Y:integer):boolean;
{ Private declarations }
public
QueenPosArr: array of TQueenPos;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SearchStart();
end;
procedure TForm1.SearchStart();
var
i, j: integer;
begin
setLength(QueenPosArr, CBoardSize);
for i:=0 to CBoardSize-1 do
begin
QueenPosArr[i].X := -1;
QueenPosArr[i].Y := -1;
end;
for i:=0 to CBoardSize-1 do
begin
QueenPosArr[0].X := 0;
QueenPosArr[0].Y := i;
showMessage(inttostr(i));
if getNextQueenPos(0, QueenPosArr[i].X, QueenPosArr[i].Y) then
begin
for j:=0 to CBoardSize-1 do
begin
showMessage(inttostr(QueenPosArr[j].X)+'-'+inttostr(QueenPosArr[j].Y));
end;
end
else
begin
end;
end;
end;
function TForm1.getNextQueenPos(index, X, Y:integer):boolean;
var
i: integer;
nowIndex: integer;
begin
for i:=0 to CBoardSize-1 do
begin
nowIndex := index+1;
QueenPosArr[nowIndex].X := nowIndex;
QueenPosArr[nowIndex].Y := i;
if checkRule(QueenPosArr[nowIndex].X, QueenPosArr[nowIndex].Y) then
begin
if nowIndex = 7 then
begin
result := true;
exit;
end
else
begin
if getNextQueenPos(nowIndex, QueenPosArr[nowIndex].X, QueenPosArr[nowIndex].Y) then
begin
result := true;
exit;
end
else
begin
QueenPosArr[nowIndex].X := -1;
QueenPosArr[nowIndex].Y := -1;
end;
end;
end
else
begin
QueenPosArr[nowIndex].X := -1;
QueenPosArr[nowIndex].Y := -1;
if i = CBoardSize-1 then
begin
result := false;
end;
end;
end;
end;
function TForm1.checkRule(X,Y:integer):boolean;
var
i: integer;
begin
for i:=0 to X-1 do
begin
if QueenPosArr[i].X > -1 then
begin
if (X=QueenPosArr[i].X) or (Y=QueenPosArr[i].Y) or ((Y-X)=(QueenPosArr[i].Y-QueenPosArr[i].X)) or ((Y+X)=(QueenPosArr[i].Y+QueenPosArr[i].X)) then
begin
result := false;
exit;
end;
end;
end;
result := true;
end;
end.
~cpp
<script>
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
CBoardSize = 8;
type
TQueenPos = record
X: integer;
Y: integer;
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure SearchStart();
function getNextQueenPos(index, X, Y:integer):boolean;
function checkRule(X,Y:integer):boolean;
{ Private declarations }
public
QueenPosArr: array of TQueenPos;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SearchStart();
end;
procedure TForm1.SearchStart();
var
i: integer; // <------ ๋ณ์ ์ญ์ ...
begin
setLength(QueenPosArr, CBoardSize);
for i:=0 to CBoardSize-1 do
begin
QueenPosArr[i].X := -1;
QueenPosArr[i].Y := -1;
end;
for i:=0 to CBoardSize-1 do
begin
QueenPosArr[0].X := 0;
QueenPosArr[0].Y := i;
showMessage(inttostr(i));
if getNextQueenPos(0, QueenPosArr[i].X, QueenPosArr[i].Y) then
begin
end
else
begin
end;
end;
end;
function TForm1.getNextQueenPos(index, X, Y:integer):boolean;
var
i, j: integer; //<------- ๋ณ์ ์ถ๊ฐ
nowIndex: integer;
begin
for i:=0 to CBoardSize-1 do
begin
nowIndex := index+1;
QueenPosArr[nowIndex].X := nowIndex;
QueenPosArr[nowIndex].Y := i;
if checkRule(QueenPosArr[nowIndex].X, QueenPosArr[nowIndex].Y) then
begin
if nowIndex = 7 then
begin
//************************************* ์ด์ชฝ์์ ์ถ๋ ฅํ๋ ๋ฐฉ์์ผ๋ก ๋ณํ
for j:=0 to CBoardSize-1 do
begin
showMessage(inttostr(QueenPosArr[j].X)+'-'+inttostr(QueenPosArr[j].Y));
end;
//*************************************
result := true;
exit;
end
else
begin
if getNextQueenPos(nowIndex, QueenPosArr[nowIndex].X, QueenPosArr[nowIndex].Y) then
begin
result := true;
exit;
end
else
begin
QueenPosArr[nowIndex].X := -1;
QueenPosArr[nowIndex].Y := -1;
end;
end;
end
else
begin
QueenPosArr[nowIndex].X := -1;
QueenPosArr[nowIndex].Y := -1;
if i = CBoardSize-1 then
begin
result := false;
end;
end;
end;
end;
function TForm1.checkRule(X,Y:integer):boolean;
var
i: integer;
begin
for i:=0 to X-1 do
begin
if QueenPosArr[i].X > -1 then
begin
if (X=QueenPosArr[i].X) or (Y=QueenPosArr[i].Y) or ((Y-X)=(QueenPosArr[i].Y-QueenPosArr[i].X)) or ((Y+X)=(QueenPosArr[i].Y+QueenPosArr[i].X)) then
begin
result := false;
exit;
end;
end;
end;
result := true;
end;
end.










