永发信息网

【runtimeerror】HDUACMproblem1236为什么会RuntimeError(ACCESS_VIOLATION)?以下...

答案:2  悬赏:30  手机版
解决时间 2021-02-04 22:18
【runtimeerror】HDUACMproblem1236为什么会RuntimeError(ACCESS_VIOLATION)?以下...
最佳答案
【答案】 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
全部回答
回答的不错
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
新人弱弱地问下,美杜莎补刀多少才算及格啊?
文誉超市在哪里啊,我有事要去这个地方
企业工会委员会可以提出增资吗,增资需要哪些
养蜥蜴没有紫外线灯和太阳灯能直接晒太阳吗?
挠闷的意思是什么啊?知道的请说下!
锅碗瓢盆五金店地址好找么,我有些事要过去
怀仁大药房会同康复堂店地址在什么地方,想过
为什么手机搜不到蓝牙耳机?
新天峰五金建材店地址在哪,我要去那里办事
上面一个日字下面一个文字念什么?
复名的意思是什么啊?知道的请说下!
十字绣家和万事兴格数502w*193h是多少ct
__penshaveyougot前边填什么A,Howmuch_B,How
电焊工证在网上能查到吗求回答!!
小汪五金建材店地址在什么地方,我要处理点事
推荐资讯
产生同分异构体的原因,
员工在节假日外出后因天气恶劣导致无法回到公
【甲a联赛】以下是2003年全国足球甲A联赛积分
乙酸乙酯 为什么要用食盐水洗涤?是否可以用水
王鹏眼镜(温州总店)地址有知道的么?有点事想
玩电脑带平光眼镜可以防辐射么
如何拍出背景暗,主体亮的照片
梦幻西游三染要多少钱?
我好羡慕别人的男朋友送花给自己女朋友还定蛋
环境纠纷的意思是什么啊?知道的请说下!
辞貌的意思是什么啊?知道的请说下!
(5分)以下是植物茎中与运输有关的两种管道
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?