돌아버리게츠요 ㅠㅠ
큰맘
질문 제목 : 질문 내용 :
#includestdio.h
#includestring.h
//스택 사이즈, 탈출 좌표등 전처리
#define stack_size 100
#define exit_row 11
#define exit_col 15
#define true 1
#define false 0
//동서남북 방향 탐색을 위한 구조체 선언과 초기화
typedef struct{
int x;
int y;
} direction;
direction move[8]={{-1,0},{-1,-1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
//위치정보를 위한 구조체
typedef struct{
int row;
int col;
int dir;
} place;
place stack[stack_size];
place position;
int top,row,col,next_row,next_col,dir,found=false;
void add(int *top, place position);
place del(int *top);
void main()
{
int i,j;
//방문한곳을 표시하기위한 visit배열과 미로배열 선언,초기화
int visit[12][16]={0,};
int maze[13][17]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1},
{1,1,0,0,0,1,1,0,1,1,1,0,0,1,1,1,1},
{1,0,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1},
{1,1,1,0,1,1,1,1,0,1,1,0,1,1,0,0,1},
{1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1},
{1,0,0,1,1,0,1,1,1,0,1,0,0,1,0,1,1},
{1,0,0,1,1,0,1,1,1,0,1,0,0,1,0,1,1},
{1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1},
{1,1,1,0,0,0,1,1,0,1,1,0,0,0,0,0,1},
{1,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,0,1,1,1,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
for(i=0;i13;i++)
{
printf(\n);
for(j=0;j17;j++)
{
printf(%2d,maze[i][j]);
}
}
printf(\n\n);
//출발점을 방문 체크하고 첫번째 스택에 저장
visit[1][1]=1;
top=0;
stack[0].row=1;
stack[0].col=1;
stack[0].dir=0;
//도착점을 찾거나 길이 없는경우 while 문 벗어남
while(top-1 && !found){
position=del(&top);
row=position.row;
col=position.col;
dir=position.dir;
//동서남북 탐색구문
while(dir8 && !found){
next_row=row+move[dir].x;
next_col=col+move[dir].y;
if(next_row==exit_row && next_col==exit_col)
found=true;
//다음 좌표가 0 이고 방문한곳도 아닐경우
//방문표시후 이전좌표를 스택에 저장후 다음좌표를 다시 위치정보 구조체에 저장
else if(!maze[next_row][next_col] && !visit[next_row][next_col])
{
visit[next_row][next_col]=1;
position.row=row;
position.col=col;
position.dir=++dir;
add(&top,position);
row=next_row;
col=next_col;
dir=0;
}
else ++dir;
}
}
if(found)
{
printf(올바른 길은\n);
for(i=0;i=top;i++)
printf((%2d, %2d)\n,stack[i].row,stack[i].col);
printf((%2d, %2d)\n,row,col);
printf((%2d, %2d)\n,exit_row,exit_col);
printf(입니다\n);
}
else
printf(출구가 없는 미로 입니다\n);
}
//스택에 위치정보 추가함수
void add(int *top, place position)
{
if(*top=stack_size-1)
{
printf(스택이 가득찼습니다\n);
return;
}
stack[++*top]=position;
}
//스택에서 위치정보를 반환하는 함수
place del(int *top)
{
if(*top==-1)
{
printf(스택이 비었습니다\n);
return;
}
return stack[(*top)--];
}/////////////실행결과////////////
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 0 0 0 1 1 0 0 0 1 1 1 1 1 1
1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1
1 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1 1
1 1 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1
1 1 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1
1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1
1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1
&nbbr /1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1
1 1 1 0 0 0 1 1 0 1 1 0 0 0 0 0 1
1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1
1 0 1 0 0 1 1 1 1 1 0 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
출구가 없는 미로 입니다
요래뜸..환장해버리겟음..어디가틀린거죠..