[求助]c++迷宫问题出错了,大佬求解答
程序代码:
/* Name: Copyright: Author: Date: 19-03-20 19:33 Description: */ #include<iostream> using namespace std; int n,m,xs,ys,xe,ye; bool flag; bool checksame(int a,int b){ if(a==xe&&b==ye)return true; flag=true; return false; } char a[100][100]; int dirx[4]={-1,1,0,0}; int diry[4]={0,0,1,-1}; bool vis[100][100]={false}; void dfs(int x,int y){ if(checksame(x,y)){ return ; } for(int i=0;i<4;++i){ int xx=x+dirx[i]; int yy=y+diry[i]; if(vis[xx][yy]!=true&&a[xx][yy]=='.'){ vis[xx][yy]=true; dfs(xx+1,yy+1); vis[xx][yy]=false; cout<<xx<<" "<<yy<<endl; } } } int main(){ cin>>n>>m>>xs>>ys>>xe>>ye; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; } } dfs(xs,ys); if(flag)cout<<"YES"; else cout<<"NO"; return 0; }