C : Runtime Error Verdict (Help debugging)

标签 c debugging runtime-error

我正在解决在线法官的问题(链接 here ),并且每次提交解决方案时我都会收到运行时错误判决。我已经看了有一段时间了,我仍然不明白它出了什么问题。我还查找了运行时错误背后的典型原因(数组超出键值、超出内存限制、逻辑错误......等)。我在下面发布的代码中找不到其中任何一个:

#include<stdio.h>

int Hall[110][110];

int isValid(int x, int y){
int i,j,cnt=0;

for(i=x-1; i<=x+1; i++)
    for(j=y-1; j<=y+1; j++)
            if(Hall[x][y]==Hall[i][j])
                cnt++;  
if(cnt>1)
    return 0;
else
    return 1;
}

int notChecked(int N,int* checked,int size){
  int i;

  for(i=0; i<size; i++)
     if(checked[i] == N)
        return 0;

  return 1;
}

int main (void){
  int T,R,C,checked[110],i,j,k,size;

  scanf("%d",&T);
  for(i=0; i<T; i++){
    scanf("%d %d",&R,&C);
    //initialize
    size=0;
    for(j=0; j<R*C; j++)    checked[j] = -1;
    for(j=0; j<=C+1; j++){
            Hall[0][j] = -1;
            Hall[R+1][j] = -1;
    }
    for(j=0; j<=R+1; j++){
            Hall[j][0] = -1;
            Hall[j][C+1] = -1;
    }
    //read input
    for(j=1; j<=R; j++)
        for(k=1; k<=C; k++)
            scanf("%d",&Hall[j][k]);

    //algo:
    for(j=1; j<=R; j++)
        for(k=1; k<=C; k++)
            if(Hall[j][k]>=0){
                if(notChecked(Hall[j][k],checked,size)){
                    if(isValid(j,k)==0){
                        checked[size] = Hall[j][k];
                        size++;
                    }
                }
            }

    printf("%d\n",size);
}

return 0;}

非常感谢任何帮助!

最佳答案

您需要对输入进行边界检查。

根据网站 T 需要介于 1 到 100 之间(含),因此您需要检查这一点。然后,对于每个 RC(网站上的 NM),它们也需要介于 1 之间100 以内。

对于每组 R by C 条目,您需要确保实际读取 R 行和 C 列。您还需要确保您阅读了 T 总条目集。

关于C : Runtime Error Verdict (Help debugging),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34753784/

相关文章:

.net - 有哪些不同的 CLR 句柄类型?

c++ - 初始化一个复杂的对象。当我不这样做时出错?

ios - Keypath not found in entity error 但我可以插入到数据存储中

javascript - 在函数堆栈内的 javascript 中记录函数/对象名称

c - c中奇怪的括号和宏语法

c - 如何读取文件、获取数据和计算

c - 为什么这个 ptrace 错误?

android - 如何看待用户提出的问题,我们这边无法模拟

C-在 if-else if 部分的赋值中得到不兼容的类型

c++ - C++ H文件问题