c语言迷宫问题 急求

实验内容:迷宫的队实现。要求构建校园地图(如下),输入任意的起点终点,可以指出一条路径。迷宫(及路径)的图形化参见下文。intmaze[14][28]=//迷宫举例:校园... 实验内容:迷宫的队实现。要求构建校园地图(如下),输入任意的起点终点,可以指出一条路径。迷宫(及路径)的图形化参见下文。
int maze[14][28]= //迷宫举例:校园地图
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

for(i=0;i<14;i++) //迷宫图形化输出
{
for(j=0;j<28;j++)
{
if(maze[i][j]==1)
cout<<"■";
else cout<<"□";
}
cout<<endl;
}
就是这样。。语言0基础 上来就留了这么个作业 求助
展开
 我来答
创世纪era
2013-10-19 · TA获得超过106个赞
知道小有建树答主
回答量:101
采纳率:100%
帮助的人:72.8万
展开全部
1是路径还是0是路径?
#include<cstdio>
#include<cstdlib>
enum se{
path,
block,
end,
mark
};
struct way{
int x;
int y;
}record[1000];
int maze[14][28]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
void set_end(int ex, int ey){ //设置结束
maze[ex][ey] = end;
}
void printMaze(){
for(int i=0;i<14;i++) //迷宫图形化输出
{
for(int j=0;j<28;j++)
{
if(maze[i][j] == block)
printf("■");
else printf("□");
}
printf("\n");
}
}
void printResult(int length){
for(int i = 0; i < 14; i++) //迷宫路径图形化输出
{
for(int j = 0; j < 28; j++)
{
if(maze[i][j] == mark)
printf(">>");
else if(maze[i][j] == block)
printf("■");
else if(maze[i][j] == end)
printf("<<");
else if(maze[i][j] == path)
printf("□");
}
printf("\n");
}
for(int x = 0; x < length - 1; x++){
printf("<%d,%d> ->", record[x].x, record[x].y);
}
printf("<%d,%d> ", record[x].x, record[x].y);
printf("\n");
}
void search_path(int x, int y, int length){ // 递归寻找路径
if(maze[x][y] == end){
printResult(length);
system("pause");
exit(0);
}
else{
if(maze[x + 1][y] != block && maze[x + 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x + 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x - 1][y] != block && maze[x - 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x - 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x][y + 1] != block && maze[x][y + 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y + 1, length);
maze[x][y] = path;
length --;
}
if(maze[x][y - 1] != block && maze[x][y - 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y - 1, length);
maze[x][y] = path;
length --;
}
return;
}
}

int main(void)
{
set_end(12,26);
printMaze();
search_path(1,5,0);
printf("no path!"); //没有路径
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
1127104230
2013-10-19 · 超过12用户采纳过TA的回答
知道答主
回答量:44
采纳率:0%
帮助的人:24.5万
展开全部
#include<iostream>
using namespace std;
int main(){
int maze[14][28]= //迷宫举例:校园地图
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int i,j;

for(i=0;i<14;i++) //迷宫图形化输出
{
for(j=0;j<28;j++)
{
if(maze[i][j]==1)
cout<<"■";
else cout<<"□";
}
cout<<endl;
}
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式