scanf写错了吧
by stansxt @ 2020-04-21 10:21:13
```cpp
#include <bits/stdc++.h>
using namespace std;
struct p
{
int x,y;
} W,M;
queue<p>q;
int a[1001][1001];
bool k[10000][10000];
int p[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
void BFS()
{
int len=1,ans=0;
while(!q.empty())
{
for(int i=0; i<len; i++)
{
if(q.front().x==W.x&&q.front().y==W.y)
{
printf("%d",ans);
return ;
}
for(int i=0; i<4; i++)
{
if(a[q.front().x+p[i][0]][q.front().y+p[i][1]]&&!k[q.front().x+p[i][0]][q.front().y+p[i][1]])
{
M.x=q.front().x+p[i][0];
M.y=q.front().y+p[i][1];
q.push(M);
k[M.x][M.y]=1;
}
}
q.pop();
}
ans++;
len=q.size();
}
}
int main()
{
int n;
char x;
scanf("%d",&n);
getchar();
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%c",&x);
a[i][j]=(x=='0');
}
getchar();
}
scanf("%d%d%d%d",&M.x,&M.y,&W.x,&W.y);
q.push(M);
k[M.x][M.y]=1;
BFS();
return 0;
}
```
楼主的code
by asasas @ 2020-04-21 10:23:21
哦这不是经典锅吗
by return20071007HNO3 @ 2020-04-21 10:26:38
@[栾竹清影](/user/288716) 字符读入要用cin或者用scanf读字符串的第一位
by K0stlin @ 2020-04-21 10:27:09
```cpp
scanf("%c",&x);
```
直觉告诉我,这里会有问题~~(即使我没看题)~~
by 童年如作业 @ 2020-04-21 10:27:24
的确挺经典
by K0stlin @ 2020-04-21 10:27:30
```
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%c",&x);
a[i][j]=(x=='0');
}
getchar();
}
```
如果结尾是 '/r/n' 怎么办
by Trinitrotoluene @ 2020-04-21 10:27:45
不懂啊。。。蒟蒻来凑热闹
by Micro_Seven @ 2020-04-21 10:28:00
@[栾竹清影](/user/288716) `do scanf("%c",&x);while(!isdigit(x));`
by return20071007HNO3 @ 2020-04-21 10:28:42
AC了~~真棒~~
by return20071007HNO3 @ 2020-04-21 10:28:52