1004成绩排名C语言,1004 成绩排名最后一个测试点显示运行错误

#include<stdio.h>

int main()

{   int n,i;

int max=0,min=0,p1=0,p2=0;

struct Student{

char name[11];

char number[11];

int score;

}student[100];

scanf("%d",&n);

for(i=0;i<n;i++)

{

scanf("%s %s %d",&student[i].name,&student[i].number,&student[i].score);

}

for(i=0;i<n;i++)

{

if(student[i].score>max)

{

max=student[i].score;

p1=i;

}

if(student[i].score<min)

{

min=student[i].score;

p2=i;

}

}

printf("%s %s\n",student[p1].name,student[p1].number);

printf("%s %s\n",student[p2].name,student[p2].number);

return 0;

}

前两个测试点都过了就是第三个过不了

个人感觉时输入缓冲区的问题。

还有别用scanf_s连着输入,会出很多意想不到的问题。

f65cfc101ce4a9fc019a4627d55ff950.png

#include<stdio.h>

int main() {

int n, i;

int max = 0, min = 0, p1 = 0, p2 = 0;

struct Student {

char name[11];

char number[11];

int score;

}student[100];

scanf_s("%d", &n);

for (i = 0; i < n; i++) {

char c; // 清空输入缓冲区

while ((c = getchar()) != '\n');

//scanf_s("%s %s %d", student[i].name, student[i].number, &student[i].score);

gets_s(student[i].name, 11);

gets_s(student[i].number, 11);

scanf_s("%d", &student[i].score);

}

for (i = 0; i < n; i++) {

if (student[i].score > max) {

max = student[i].score;

p1 = i;

}

if (student[i].score < min) {

min = student[i].score;

p2 = i;

}

}

printf("%s %s\n", student[p1].name, student[p1].number);

printf("%s %s\n", student[p2].name, student[p2].number);

return 0;

}

73bccf0c0b4af35beddca4274520fb45.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值