结构体和二维数组的应用
#include <iostream>
using namespace std;
struct enter
{
int row;
int col;
};
int main()
{
int array[4][4]={{1,1,0,1},{1,1,2,1},{1,0,0,1},{3,0,1,1}};//数组元素
enter enter_box; //箱子的位置
enter_box.row=1; //箱子的行
enter_box.col=2; //箱子的列
for(int i=enter_box.row;i<4;i++)//从上到下,从右到左搜索元素为0的位置
{
for(int j=enter_box.col;j>=0;j--)
{
if(array[i][j]==0) //继续搜索
{
enter_box.row=i;
enter_box.col=j;
cout<<"("<<enter_box.row<<","<<enter_box.col<<")->";
}
else if(array[i][j]==1)
{}
else if(array[i][j]==3)
{
cout<<"到达目的地"<<endl;
}
else
{}
}
}
return 0;
}