돌아버리게츠요 ㅠㅠ
큰맘
질문 제목 : 질문 내용 :
#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
출구가 없는 미로 입니다
요래뜸..환장해버리겟음..어디가틀린거죠..
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |