C 我可以';我无法解决。运行时SIGSEGV
我在codechef上尝试这个问题 据我检查,输出结果是正确的。 但是当我在codechef上提交它时,一个C 我可以';我无法解决。运行时SIGSEGV,c,runtime-error,segmentation-fault,C,Runtime Error,Segmentation Fault,我在codechef上尝试这个问题 据我检查,输出结果是正确的。 但是当我在codechef上提交它时,一个运行时错误即将到来(SIGSEGV) 请帮我找到这个问题的解决办法 #包括 #包括 int main() { int m=0; 长整数i=0,j=0,c=0,t=0,v=0,a=0; 长整数n=0,q=0,x[10]={0},y[10]={0},s[10]={0},f[10]={0}; 长int p[10][10]={0},cl[10]={0}; /*阵列-- x和y表示坐标 s和f表示
运行时错误
即将到来(SIGSEGV)
请帮我找到这个问题的解决办法
#包括
#包括
int main()
{
int m=0;
长整数i=0,j=0,c=0,t=0,v=0,a=0;
长整数n=0,q=0,x[10]={0},y[10]={0},s[10]={0},f[10]={0};
长int p[10][10]={0},cl[10]={0};
/*阵列--
x和y表示坐标
s和f表示行程的开始和结束
p是表示差异的二维数组
用于存储最小值的cl
*/
//printf(“输入测试用例的数量”);
scanf(“%d”、&t);
对于(m=0;m)您的运行时是什么inputs@ArjunSreedharan错误不应依赖于运行时输入。代码必须足够健壮,以处理任何输入。我在代码中看到一个错误,它可能会导致问题,也可能不会导致问题,您忽略scanf()的返回值
这可能会导致未定义的行为。在这里访问数组索引是基于输入的n
。可能是访问超限内存,因此检查它们的值可以防止出现这种情况,并且不会出现错误,这适用于(i=s[v]-1;i
#include<stdio.h>
#include<math.h>
int main()
{
int m=0;
long int i=0,j=0 ,c=0,t=0,v=0,a=0 ;
long int n=0,q=0,x[10]={0},y[10]={0},s[10]={0},f[10]={0};
long int p[10][10]={0},cl[10]={0};
/*arrays--
x and y for coordinates
s and f for start and finish of the trips
p is 2-d array for differences
cl for storing minimums
*/
//printf("Enter the number of test cases");
scanf("%d",&t);
for(m =0;m <t;m++)//test cases
{
//printf("Enter the number of chambers\n");
scanf("%ld",&n);//number of chambers
for(i=0;i<n;i++)//co-ordinates
scanf("%ld%ld",&x[i],&y[i]);
//printf("Enter the number of trips q\n");
scanf("%ld",&q);//no. of trips
for(i=0;i<q;i++)//the trips
scanf("%ld%ld",&s[i],&f[i]);
for(i=0;i<n-1;i++)//loop for calculating the difference between the co ordinates
for(j=i;j<n-1;j++)
p[i][j]=abs(x[i]-x[j+1])+abs(y[i]-y[j+1]);
/*for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
printf("%d\t",p[i][j]);
printf("\n");
}*/
for(v=0;v<q;v++) //loop for the no. of times the trips
{
a=0;
for(i=s[v]-1;i<f[v]-1;i++)
{
cl[a]=p[i][i];
for(j=i;j<f[v]-1;j++)
{
if(p[i][j]<cl[a])
cl[a]=p[i][j];
}
a++;
}
/*for(i=0;i<a;i++)
printf("%d\n",cl[i]);*/
c=cl[0];
for(i=0;i<a;i++)
{
if(cl[i]>c)
c=cl[i];
cl[i]=0;
}
printf("%ld\n",c);
}
}
return 0;
}