include<stdio.h>
#include<string.h>
typedef struct
{
char name[20];
char ID[20];
int rpt[5];
double ave;
int tot;
}stu;
int main()
{
stu s1[101];
int n; scanf("%d", &n);
for (int m = 0; m < n; m++) {
getchar();
fgets(s1[m].name,25 , stdin);
fgets(s1[m].ID, 25, stdin);
char*find1 = strchr(s1[m].name, '\n');
char*find2 = strchr(s1[m].ID, '\n');
if (find1) *find1 = '\0';
if (find2) *find2 = '\0';
//gets(s1[m].name);
//gets(s1[m].ID);
for (int i = 0; i < 5; i++)
scanf("%d", &s1[m].rpt[i]);
printf("Name:%s\nID:%s\nScore:", s1[m].name, s1[m].ID);
s1[m].tot = 0;
for (int i = 0; i < 4; i++)
{
printf("%d ", s1[m].rpt[i]);
s1[m].tot += s1[m].rpt[i];
}
printf("%d\n", s1[m].rpt[4]);
s1[m].tot += s1[m].rpt[4];

if (s1[m].tot > 0) s1[m].ave = s1[m].tot / 5.0;
else s1[m].ave = 0.00;
printf("average:%.2f total:%d\n\n", s1[m].ave, s1[m].tot);
}
return 0;
}

代码如上,最后一个测试点出现运行时错误,老师能帮忙看下吗?万分感谢

Comments  

# Moderator 2021-12-20 10:49
https://bbc3502.hopto.org/c2021/index.php/home-17/618-7-59-11-3
测试数据
# Moderator 2021-12-19 23:08
试试这个数据
4
xiaowang121234567890
0821131699999
87 98 79 90 68
Liu Mengmeng3456789
0821131666666
88 90 93 91 85
Albert Einstein34567890
0821131477777
75 87 100 66 64
Bill Gates345678903456
0821131588888
65 58 77 60 61

You have no rights to post comments