下面是对问题的描述https://a2oj.com/p?ID=193,它在Visual Studio上运行得非常好,但由于某种原因,它产生运行时 - 网站的在线判断编译器出错,很难检测到因为他们的编译器不会告诉测试用例产生了什么错误。运行时错误 - C编程,在IDE上没有错误
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ASCII_SIZE 255
void main(){
int testCases;
char caseInput[100];
int count[ASCII_SIZE] = {0};
int strLength;
int max = -1;
char result = NULL;
typedef struct occurrence{
int numOfOcc;
char occLetter; }Occurence;
scanf("%d",&testCases);
Occurence *ptr;
ptr = (Occurence*)malloc(testCases * sizeof(Occurence));
if (ptr){
for (int caseValue = 0; caseValue < testCases; caseValue++)
{
scanf("%s",caseInput);
strLength = strlen(caseInput);
for (int i=0; i<strLength; i++)
count[caseInput[i]]++;
for (int i = 0; i < strLength; i++) {
if (max <= count[caseInput[i]]) {
if (result > caseInput[i] && i > 0){
max = count[caseInput[i]];
result = caseInput[i];
}
else if (i == 0){
max = count[caseInput[i]];
result = caseInput[i];
}
}
}
ptr[caseValue].numOfOcc = max;
ptr[caseValue].occLetter = result;
max = -1;
char result = NULL;
memset(count,0,sizeof(count));
}
for (int i = 0; i < testCases; i++)
{
printf("%d %c\n",ptr[i].numOfOcc,ptr[i].occLetter);
}
}
}
我已经在他们的编译器/测试平台上看到过这个:你的'void main()'是一个相关的错误声明,必须是'int main'。因此,您的'main'返回一个未定义的值,他们的测试床将其解释为错误,因此会报告运行时错误。它返回0. –
是的,谢谢我这样做,但现在它说错误的答案,因为某些原因,虽然它在IDE上运行得非常好,并且它的编译器没有说出哪个测试用例使代码失败是不好的 – andrewnagyeb