大牛快来帮我啊,写了一个程序,检测没问题,运行就直接挂掉了,怎么回事啊

丶麦麦麦 2015-11-02 09:39:36
#include<stdio.h>;
#include<string.h>;
#include<stdlib.h>;
struct student
{
char name[100];
int num[1000];
int score;
};
int compare1(const void *a,const void *b)
{
return ((student*)b)->score - ((student*)a)->score;
}

int compare2(const void *a,const void *b)
{
return *(((student*)a)->name) - *(((student*)b)->name);
}
void print(student s)
{
printf("%s %d\n", s.name, s.score);
}
int main()
{
student s[1000];
student ne[1000];
int n,m,g;
int t;
int a[1000];
int i,j;
while(scanf("%d%d%d",&n,&m,&g)!=EOF)
{

for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
scanf("%s%d",s[i].name,&t);
getchar();
for(j=0;j<t;j++)
{
scanf("%d",&s[i].num[j]);
}
}
int p=0;
int r[1000]={0};
for(i=0;i<n;i++)
{
s[i].score=0;
for(j=0;j<t;j++)
{
s[i].score+=a[s[i].num[j]-1];
}
int k=0;
if(s[i].score>=g)
{

//memcpy(ne[p],s[i],sizeof(s[i]));
strcpy(ne[p].name,s[i].name);
ne[p].score=s[i].score;
p++;
}
}
qsort(ne, p, sizeof(student), compare2);
qsort(ne, p, sizeof(student), compare1);
printf("%d\n",p);
for(i = 0; i < p; i++)
{
print(ne[i]);
}
}
return 0;
}
测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N
< 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一
名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。



...全文
103 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-11-03
  • 打赏
  • 举报
回复
static student s[1000]; static student ne[1000]; 在占用内存空间较大的局部数组声明的前面加static将其从堆栈数据段挪到全局数据段即可避开因局部数组大小超过默认堆栈大小1MB造成程序不能正常运行的问题。
丶麦麦麦 2015-11-03
  • 打赏
  • 举报
回复
引用 2 楼 fly_dragon_fly 的回复:
测试数据是什么
Sample Input 4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0 Sample Output 3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20
fly_dragon_fly 2015-11-03
  • 打赏
  • 举报
回复
测试数据是什么
丶麦麦麦 2015-11-03
  • 打赏
  • 举报
回复
怎么没人来啊

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧