本来输入用scanf和getchar都是0分(见注释),换成cin就AC了(害得我浪费了1小时)。有没有大佬能解释一下原理?
#include<iostream>
#include<cstring>
using namespace std;
int t,n,m,k,ans,x,y,d;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
char c;
bool a[10001][10001],re[10001][10001];
int main()
{
scanf("%ld",&t);
while(t--)
{
cin>>n>>m>>k>>x>>y>>d;
memset(re,0,sizeof(re));
ans=1;
re[x][y]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>c;
if(c=='.') a[i][j]=0;
else a[i][j]=1;
}
}
while(k--)
{
int x_=x+dx[d],y_=y+dy[d];
if(x_>=1 && x_<=n && y_>=1 && y_<=m && !a[x_][y_])
{
x=x_;
y=y_;
if(!re[x][y]) ans++;
re[x][y]=1;
}
else d=(d+1)%4;
}
printf("%ld\n",ans);
}
return 0;
}