돌아버리게츠요 ㅠㅠ
가지등
질문 제목 : 질문 내용 :
#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
출구가 없는 미로 입니다
요래뜸..환장해버리겟음..어디가틀린거죠..
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699415 | 파일//read//와 배열 | 아란 | 2025-06-25 |
2699386 | 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) | 미즈 | 2025-06-25 |
2699361 | 연결리스트 정렬하는 부분에 대해서 질문 드립니다 | 아이처럼 | 2025-06-25 |
2699304 | [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. | 놀리기 | 2025-06-24 |
2699272 | printf() 함수이용해서 프로그램 만들기 질문요! (5) | 다가 | 2025-06-24 |
2699221 | PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? | 파라미 | 2025-06-24 |
2699192 | 설치오류가 자꾸 나요 한번봐주세여~ (1) | 소녀틳향기 | 2025-06-23 |
2699161 | for loop안에 있는 if문 (9) | Orange | 2025-06-23 |
2699105 | 링크더리스트 이전 링크값 출력함수. | 꼬꼬마 | 2025-06-23 |
2699078 | 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) | 귀염포텐 | 2025-06-22 |
2699024 | C언어 공부하려는데 도와주세요!!! (2) | 달님 | 2025-06-22 |
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |