Jasper2024 @ 2024-10-27 10:34:27
by litangzheng @ 2024-10-27 10:35:57
@Jasper2024 运行错误,根据此题你可能是数组越界or爆栈or死循环。
by gjh0112 @ 2024-10-27 10:36:26
运行错误,一般指针越界,数组开小
by Jasper2024 @ 2024-10-27 11:07:55
#include <iostream>
using namespace std;
int main()
{
int i,t;
cin>>t;
for(i=0;i<t;i++)
{
int n,m,k,x,y,d,x1,y1,sum=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
char a[n][m];
for(int j=1;j<=n;j++)
for(int q=1;q<=m;q++)
cin>>a[j][q];
for(int j=0;j<k;j++)
{
if(d==0)
{
x1=x;
y1=y+1;
}
else if(d==1)
{
x1=x+1;
y1=y;
}
else if(d==2)
{
x1=x;
y1=y-1;
}
else if(d==3)
{
x1=x-1;
y1=y;
}
if(x1<1||x1>n||y1<1||y1>m||a[x1][y1]=='x')
{
d=d+1;
d=d%4;
}
else if(x1>=1&&x1<=n&&y1>=1&&y1<=m&&a[x1][y1]!='x')
{
x=x1;
y=y1;
if(a[x1][y1]=='.')
sum++;
a[x1][y1]=',';
}
}
cout<<sum<<endl;
}
return 0;
}