【runtimeerror】HDUACMproblem1236为什么会RuntimeError(ACCESS_VIOLATION)?以下...
答案:2 悬赏:30 手机版
解决时间 2021-02-04 22:18
- 提问者网友:人傍凄凉立暮秋
- 2021-02-04 18:01
【runtimeerror】HDUACMproblem1236为什么会RuntimeError(ACCESS_VIOLATION)?以下...
最佳答案
- 五星知识达人网友:舊物识亽
- 2021-02-04 19:11
【答案】 Runtime Error (ACCESS_VIOLATION)原因可能是:
(1)int num[5]不够,当一个学生解决的题目总数>5时越界;
(2)malloc的student没有free
另外:
(1)函数judge可能有问题,用strcmp代替;
(2)为保证正确free,要交换student的数据而不是指针.
以下修改AC:
#include
#include
#include
struct stu
{
char id[21];
int solved;
int num[10];//int num[5];
int score;
};
int judge(char a[20],char b[20])
{
int length_a;
int length_b;
length_a = strlen(a);
length_b = strlen(b);
if(length_a length_b)
return 2;
else
{
for(int i=0; i b[i])
{
return 2;
break;
}
}
}
};
void main()
{
int men;
int num;
int passline;
while(scanf(%d,&men)!=EOF)
{
if(men == 0)
break;
scanf(%d %d,&num,&passline);
int section[10];
struct stu *student[1000];
for(int i=0; iscore = 0;
scanf(%d,&student[j]->solved);
for(int k=0; ksolved; k++)
{
scanf(%d,&student[j]->num[k]);
student[j]->score+=section[student[j]->num[k]-1];
}
}
int count=0;
struct stu *temp;
//temp = (stu *)malloc(sizeof(struct stu));
for(int l=0; lscore >= passline)
{
*student[count] = *temp;//student[count] = temp;
count++;
}
}
struct stu temp2;//added
for(int x=1; xscore)
{
temp2 = *student[y-1];//temp = student[y-1];
*student[y-1] = *student[y];//student[y-1] = student[y];
*student[y] = temp2;//student[y] = temp;
}
else if(student[y-1]->score == student[y]->score)
{
//if(judge(student[y-1]->id ,student[y]->id) == 2)
if(strcmp(student[y-1]->id ,student[y]->id) > 0)
{
temp2 = *student[y-1];//temp = student[y-1];
*student[y-1] = *student[y];//student[y-1] = student[y];
*student[y] = temp2;//student[y] = temp;
}
}
}
}
printf(%d\n,count);
for(int z=0; zid,student[z]->score);
}
for(int k=0; k
(1)int num[5]不够,当一个学生解决的题目总数>5时越界;
(2)malloc的student没有free
另外:
(1)函数judge可能有问题,用strcmp代替;
(2)为保证正确free,要交换student的数据而不是指针.
以下修改AC:
#include
#include
#include
struct stu
{
char id[21];
int solved;
int num[10];//int num[5];
int score;
};
int judge(char a[20],char b[20])
{
int length_a;
int length_b;
length_a = strlen(a);
length_b = strlen(b);
if(length_a length_b)
return 2;
else
{
for(int i=0; i b[i])
{
return 2;
break;
}
}
}
};
void main()
{
int men;
int num;
int passline;
while(scanf(%d,&men)!=EOF)
{
if(men == 0)
break;
scanf(%d %d,&num,&passline);
int section[10];
struct stu *student[1000];
for(int i=0; iscore = 0;
scanf(%d,&student[j]->solved);
for(int k=0; ksolved; k++)
{
scanf(%d,&student[j]->num[k]);
student[j]->score+=section[student[j]->num[k]-1];
}
}
int count=0;
struct stu *temp;
//temp = (stu *)malloc(sizeof(struct stu));
for(int l=0; lscore >= passline)
{
*student[count] = *temp;//student[count] = temp;
count++;
}
}
struct stu temp2;//added
for(int x=1; xscore)
{
temp2 = *student[y-1];//temp = student[y-1];
*student[y-1] = *student[y];//student[y-1] = student[y];
*student[y] = temp2;//student[y] = temp;
}
else if(student[y-1]->score == student[y]->score)
{
//if(judge(student[y-1]->id ,student[y]->id) == 2)
if(strcmp(student[y-1]->id ,student[y]->id) > 0)
{
temp2 = *student[y-1];//temp = student[y-1];
*student[y-1] = *student[y];//student[y-1] = student[y];
*student[y] = temp2;//student[y] = temp;
}
}
}
}
printf(%d\n,count);
for(int z=0; zid,student[z]->score);
}
for(int k=0; k
全部回答
- 1楼网友:千杯敬自由
- 2021-02-04 19:47
回答的不错
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯