#include <iostream>
#include <stdio.h>
using namespace std;
int ei=6,ej=6;
int maze[8][8]={{1,1,1,1,1,1,1,1},
{1,0,0,0,1,0,0,1},
{1,1,1,0,0,0,1,1},
{1,0,0,1,1,0,0,1},
{1,1,0,0,0,0,1,1},
{1,1,0,1,0,0,0,1},
{1,0,0,1,1,0,0,1},
{1,1,1,1,1,1,1,1}};
int vi(int i,int j)
{
int suc = 0;
maze[i][j] = 2;
if (i == ei && j == ej)
suc = 1;
if (suc != 1 && maze[i][j+1] == 0)
suc = vi(i,j+1);
if (suc != 1 && maze[i+1][j] == 0)
suc = vi(i+1,j);
if (suc != 1 && maze[i][j-1] == 0)
suc = vi(i,j-1);
if (suc != 1 && maze[i-1][j] == 0)
suc = vi(i-1,j);
if (suc != 1)
maze[i][j] = 0;
return suc;
}
int main(void)
{
int i,j,si,sj;
cout <<"请输入出发点的x座标(0-7):\n";
cin >> si;
cout <<"请输入出发点的y座标(0-7):\n";
cin >> sj;
cout <<"迷宫出发前:\n";
for (i=0;i<8;i++)
{
for (j=0;j<8;j++)
{
if (maze[i][j] == 1)
cout <<"●";
else
cout <<" ";
}
cout <<"\n";
}
if (vi(si,sj) != 1)
cout <<"没有找到出口!"<<endl;
else
{
cout <<"迷宫走的路线:\n";
for (i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
if (maze[i][j] == 1)
cout <<"●";
else if(maze[i][j] == 2)
cout <<"◎";
else
cout <<" ";
}
cout <<"\n";
}
}
return 0;
}