[PAT-A 1036]Boys vs Girls

在这里插入图片描述
题目大意:
给出N个同学的信息,输出女生之中的最高分数获得者和男生之中最低分数获得者的姓名学号与两个乘积之差

思路:
1.定义结构体person保存学生信息,包括姓名,学号,性别,分数
2.定义F_lowest与M_highest保存男生中最高分获得者与女生之中最低分获得者,初始化男生最低分101,女生最高分-1
3.用temp保存输入,并判断
4.输出,注意没有女生/男生的情况

AC代码:

	//PAT_A 1036
	#include<cstdio>
	using namespace std;
	struct person {
		char name[15];
		char id[15];
		char gender;
		int gread;
	}M_lowest, F_highest, temp;
	void init() {
		M_lowest.gread = 101;
		F_highest.gread = -1;
	}
	int main() {
		init();
		int n;
		(void)scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			(void)scanf("%s %c %s %d", temp.name, &temp.gender, temp.id, &temp.gread);
			if (temp.gender == 'F' && temp.gread > F_highest.gread)F_highest = temp;
			else if (temp.gender == 'M' && temp.gread < M_lowest.gread)M_lowest = temp;
		}
		if (F_highest.gread == -1)printf("Absent\n");
		else printf("%s %s\n", F_highest.name, F_highest.id);
		if (M_lowest.gread == 101)printf("Absent\n");
		else printf("%s %s\n", M_lowest.name, M_lowest.id);
		if (F_highest.gread == -1 || M_lowest.gread == 101)printf("NA");
		else printf("%d", F_highest.gread - M_lowest.gread);
		return 0;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值