题目

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. Oracle的pl/sql变量类型

    pl/sql定义 sql是结构化查询语言.sql是不是一个编程语言?编程语言一般都能够声明变量,写条件判断,循环.sql不具备这些特征,所有sql不是一门编程语言.我们在实际的开发中,有这种需要,把s ...

  2. 一步一步教你PowerBI数据分析:制作客户RFM数据分析

    客户分析就是根据客户信息数据来分析客户特征,评估客户价值,从而为客户制订相应的营销策略与资源配置.通过合理.系统的客户分析,企业可以知道不同的客户有着什么样的需求,分析客户消费特征与商务效益的关系,使 ...

  3. 关于 k210 的 micropython 添加 ussl 模块,实现 https 访问支持的那些事。

    起因 事情已经过去快一周了吧,继上次修复 maixpy k210 的 esp8285 at 通信后,突然遇到泽畔大大问,要不要做 ussl 的支持? 评估了一下各方的实现,想了一下自己也刚好在做网络层 ...

  4. PHP导出excel文件,第一步先实现PHP模板导出不带数据

    今天继续研究PHP导出excel文件,把复杂的事情简单化,一步步实现功能,首先实现模板文件的导出,随后再实现写入数据后导出,最终实现功能,这是基本思路.中间可以加一步,先自己写入数据导出试试,随后再数 ...

  5. python读取excel所有数据(cmd界面)

    python读取excel所有数据(cmd界面) cmd界面显示excel数据 代码 import xlrd import os from prettytable import PrettyTable ...

  6. qt creator源码全方面分析(4-6)

    目录 Qt插件基础 Qt插件基础 我们知道Qt Creator源码是基于插件架构的,那么我们先来介绍下插件基础知识. 相关内容如下: How to Create Qt Plugins [ - Defi ...

  7. Linux vim 常用命令(不定时update)

    1.退出 先esc  再:q 2.保存退出 先Esc 再:wq 3.强制退出 先Esc 再:q! 4.寻找关键字 先 shift+ 再/keyword 5.查看行数 set nu 6.跳到指定行(例如 ...

  8. 【白嫖】IT笔试面试真题讲解系列文章+视频

    视频讲解IT公司面试的高频考题~ 持续更新中,欢迎点赞转发~ 干货|名企高频考点指令篇-查看Linux硬盘空间使用情况 干货 | 名企高频考点指令篇-Linux查看CPU内存和系统版本 干货 | 名企 ...

  9. python监听、操作键盘鼠标库pynput详细教程

    § 0.0.0 前言 监听.操作鼠标.键盘是实现自动化的捷径,比如我实现自动化签到用到了模拟键盘操作. pynput是监听.操控鼠标和键盘的跨平台第三方python库. 你可以通过pip insnal ...

  10. Copy与mutableCopy的个人理解

    Copy与mutableCopy的个人理解 1. 相同点 都是将原有对象进行深拷贝(狭义) 这里的狭义上的深拷贝指的是在不考虑编译器在编译时对不可变对象进行copy时采取的优化策略:即将不可变对象的地 ...