#include <iostream>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct gaga
{int x,y;}tp;
queue <gaga> q;
//char map[101][101];
int vist[101][101],x,y,X,Y,m,n,c=0;
int canGo(int x1,int y1)
{
cout <<"\ncome there0\n\t";
if(x1>n) return 0;cout <<"come there10\t";
if(y1>m) return 0;cout <<"come there11\t";
if(x1<1) return 0;cout <<"come there12\t";
if(y1<1) return 0;cout <<"come there13\t";
if(vist[x1][y1]!=0) return 0;cout <<"come there2\t";
vist[x1][y1]=c;
tp={x1,y1};
q.push(tp);
return 0;
}
int main()
{
int n,i,j,t;
memset(vist,0,sizeof(vist));
cin >> n>> m>> x>> y;
tp={x,y};q.push(tp);
while(!q.empty())
{
cout <<"in there while()\n";
X = q.front().x;
Y = q.front().y;
canGo(X-1,Y-2);
canGo(X+1,Y-2);
canGo(X-1,Y+2);
canGo(X+1,Y+2);
canGo(X-2,Y-1);
canGo(X-2,Y-1);
canGo(X+2,Y-1);
canGo(X+2,Y+1);
q.pop();
c++;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout << vist[i][j]<<" ";
}
cout << endl;
}
return 0;
}
请各位 dalao 帮忙看一下本jiruo的代码,加了点打印,大概是在函数canGo这里的if语句判断错误的,谢谢谢谢谢