为什么这串代码运行时没报错,但输入时却显示程序出现了一个问题?
#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,k;
int x,y,d;
char gmap[1001][1001];
int vis[1001][1001];
int ans;
int main(){
std::ios::sync_with_stdio(0),cin.tie(0);
cin>>T;
for(register int i(1);i<=T;++i){
ans=0;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(register int i=(1);i<=n;++i){
for(register int j(1);j<=m;++j){
cin>>gmap[i][j];
}
}
for(register int i(1);i<=k+1;i++){
if(!vis[x][y]){
vis[x][y]=1;
ans++;
}
if(d==0){
if(gmap[x][y+1]=='.'&&y+1<=m){
y++;
}else{
d=(d+1)%4;
}
}else if(d==1){
if(gmap[x+1][y]=='.'&&x+1<=m){
x++;
}else{
d=(d+1)%4;
}
}else if(d==2){
if(gmap[x][y-1]=='.'&&y-1>=1){
y--;
}else{
d=(d+1)%4;
}
}else if(d==3){
if(gmap[x-1][y]=='.'&&x-1>=1){
x--;
}else{
d=(d+1)%4;
}
}
}
for(register int i=(1);i<=n;++i){
for(register int j(1);i<=m;++j){
vis[i][j]=0;
}
}
cout<<ans<<endl;
}
return 0;
}