题目

This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's name, gender, ID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

Output Specification:

For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF − grade​M . If one such kind of student is missing, output Absent in the corresponding line, and output NA in the third line instead.

Sample Input 1:

3
Joe M Math990112 89
Mike M CS991301 100
Mary F EE990830 95

Sample Output 1:

Mary EE990830
Joe Math990112
6

Sample Input 2:

1
Jean M AA980920 60

Sample Output 2:

Absent
Jean AA980920
NA

题目解读

给出 N 个学生信息,名字、性别(M/F)、ID、分数,找到女生中分数最高的那个人,输出她的 名字 ID,如果不存在就输出 Absent;找到男生中分数最低的那个,输出他的名字 ID,如果不存在就输出 Absent;如果女生最高分和男生最低分都存在就输出 二者之差(女生最高分-男生最低分),如果任何一个不存在就输出 NA

思路分析

不知道这个题目为什么会有25分,感觉就是比比大小。

  • 四个变量分别保存女生最低分(初始化为-1)、这个女生(name ID)、男生最低分(初始化为101)、这个男生(name ID),每次读入一个学生信息,如果是女生就去比较更新女生最高分和对应的女生,否则就去比较更新男生最低分和对应的男生。
  • 如果女生最高分是-1,就输出 Absent,否则输出这个最高分女生的name ID
  • 如果男生最低分是101,就输出 Absent,否则输出这个最低分男生的name ID
  • 如果二者都存在就输出最高分-最低分,否则输出 NA

代码

#include <iostream>
using namespace std; int main() {
int n;
// 找女生最高分和男生最低分
string female, male;
int femalegrade = -1, malegrade = 101;
cin >> n;
while (n-- > 0) {
string name, sex, id;
int grade;
cin >> name >> sex >> id >> grade;
// 是女生
if (sex == "F") {
// 找女生最高分
if (grade > femalegrade) {
femalegrade = grade;
female = name + " " + id;
}
// 找男生最低分
} else if (grade < malegrade) {
malegrade = grade;
male = name + " " + id;
}
}
// 输出女生最高分,不存在输出 Absent
if (femalegrade == -1) cout << "Absent" << endl;
else cout << female << endl;
// 输出男生最低分,不存在输出 Absent
if (malegrade == 101) cout << "Absent" << endl;
else cout << male << endl;
// 输出二者之差,如果有一个不存在输出 NA
if (femalegrade != -1 && malegrade != 101) cout << femalegrade - malegrade;
else cout << "NA"; return 0;
}

PAT 1036 Boys vs Girls (25分) 比大小而已的更多相关文章

  1. PAT 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  2. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  3. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  4. 1036 Boys vs Girls (25分)(水)

    1036 Boys vs Girls (25分)   This time you are asked to tell the difference between the lowest grade o ...

  5. 【PAT甲级】1036 Boys vs Girls (25 分)

    题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...

  6. PAT Advanced 1036 Boys vs Girls (25 分)

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  7. PAT (Advanced Level) Practice 1036 Boys vs Girls (25 分)

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  8. PAT 1036 Boys vs Girls[简单]

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  9. PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题

    题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...

随机推荐

  1. C语言程序设计实验报告(第一次实验)

    C程序设计实验报告 实验项目:C语言程序设计教程实验1.3.2:1.3.3:1.3.4:2.3.1:2.3.2 姓名:赖瑾 实验地点:家 实验时间:2020.2.25 目录 C程序设计实验报告 一.实 ...

  2. C# 数据操作系列 - 3. ADO.NET 离线查询

    0. 前言 在上一篇中,我故意留下了查询的示范没讲.虽然说可以通过以下代码获取一个DataReader: IDataReader reader = command.ExecuteReader(); 然 ...

  3. SQLserver分库分表

    https://blog.csdn.net/ExceptionalBoy/article/details/78851327

  4. MATLAB与三大变换

    运行 Simulink 有三种方式: z 在 MATLAB 的命令窗口直接键入“Simulink”并回车: z 单击 MATLAB 工具条上的 Simulink 图标: z 在 MATLAB 菜单上选 ...

  5. Jetson AGX Xavier/Ubuntu安装SSD

    参考 https://blog.csdn.net/xingdou520/article/details/84309155 1. 查看硬盘所有分区 sudo fdisk -lu 会找到/dev/nvme ...

  6. Mysql 常用函数(5)- substring 函数

    Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html substring 的作用 截取指定范围的字符串, ...

  7. C# 数据操作系列 - 7. EF Core 导航属性配置

    在上一篇,大概介绍了Entity Framework Core关于关系映射的逻辑.在上一篇中留下了EF的外键映射没有说,也就是一对一,一对多,多对一,多对多的关系等.这一篇将为大家细细分析一下,如何设 ...

  8. redis集群复制和故障转移

    #### 一.集群的问题- 1.当某个主节点宕机后,对应的槽位没有节点承担,整个集群处于失败状态,不可用,怎么办- 2.如何判断某个主节点是否真正的岩机?- 3.如果从某个主节点的所有从节点中选举出一 ...

  9. ABAP基础2:数据类型

    数据类型-Data Type:定义程序中可以使用的数据类型,使用前要先定义 数据变量-Data Variable:参照数据类型定义的.可以存储值的变量,就是变量嘛 数据类型 数据类型在ABAP程序中用 ...

  10. JavaScript高级技术总结

    正则表达式 正则表达式的作用  正则表达式的作用: 匹配字符串的一种规则,正则表达式的作用主要是用于匹配字符串的 需求: 校验手机号 <!DOCTYPE html> <html la ...