C语言 谁总分第一(测试你对结构体数组的熟练程度)

题目描述

有N个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入N个学生的数据,要求找出总分第一且没有单科不及格的学生的数据(包括学号、姓名、3门课成绩)并输出。

结构体类型及结构体数组的定义可参考如下定义。题目没有明确说明的,均没有严格限制。

#define N 100
struct student
{
  char num[10];
  char name[10];
  int score[4];
  int total;
}stu[N];

输入

先输入学生数量N
然后每行输入一个学生的数据,包括学号、姓名、三科成绩,空格分开。

输出

总分第一且没有单科不及格的学生的数据(包括学号、姓名、3门课成绩),如果存在并列总分第一的,只输出从前往后查找遇到的第一个学生的数据。

样例输入 Copy

4
1101 clan 80 70 60
1102 blue 90 80 70
1103 xds 59 99 98
1104 bred 80 80 80

样例输出 Copy

1102 blue 90 80 70

代码

#include<stdio.h>
#include<math.h>
#include<string.h> 
#include<stdlib.h>
#define N 100

struct student
{
	int num;
	char name[10];
	int score[4];
	int total;
}stu[N];

int main()
{
	int n;
	scanf("%d",&n);
	int i,max,k=0;
	for(i=0;i<n;i++)
	{
		scanf("%d %s %d %d %d",&stu[i].num,&stu[i].name ,&stu[i].score[0] ,&stu[i].score[1],&stu[i].score[2]);
		stu[i].total=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
		
		if(i==0)max=stu[i].total;
		else
		{
				if(stu[i].total>max&&stu[i].score[2]>=60&&stu[i].score[1]>=60&&stu[i].score[0]>=60)
				{
					max=stu[i].total;
					k=i;
				}
		}
	}
	printf("%d %s %d %d %d",stu[k].num,stu[k].name ,stu[k].score[0] ,stu[k].score[1],stu[k].score[2]);
}
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shuo..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值