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 namegenderID 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 grade​F​​−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
 #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int N;
struct Node
{
string name, gender, ID;
int grade;
}node;
int main()
{
cin >> N;
vector<Node>male, female; //此代码是将数据保存下来排序,还可以直接在输入时就得到最高分和最低分,这样就大大节省了空间和时间
for (int i = ; i < N; ++i)
{
cin >> node.name >> node.gender >> node.ID >> node.grade;
if (node.gender == "M")
male.push_back(node);
else
female.push_back(node);
}
sort(male.begin(), male.end(), [](Node a, Node b) {return a.grade < b.grade; });
sort(female.begin(), female.end(), [](Node a, Node b) {return a.grade > b.grade; });
if (female.size() == )
cout << "Absent" << endl;
else
cout << female[].name << " " << female[].ID << endl;
if (male.size() == )
cout << "Absent" << endl;
else
cout << male[].name << " " << male[].ID << endl;
if (female.size() == || male.size() == )
cout << "NA" << endl;
else
cout << female[].grade - male[].grade << endl;
return ;
}

PAT甲级——A1036 Boys vs Girls的更多相关文章

  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

    1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...

  3. PAT 甲级 1036 Boys vs Girls(20)

    https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...

  4. PAT A1036 Boys vs Girls(25)

    AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...

  5. A1036. Boys vs Girls

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

  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甲级:1036 Boys vs Girls (25分)

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

  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 分)

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

随机推荐

  1. HTML基本案列

    <html> <head> <!-- meta :告诉浏览器,如何翻译汉字 http-equiv :content-type 内容类型 详细内容有后面的值指定 conte ...

  2. shiro real的理解,密码匹配等

    1 .定义实体及关系 即用户-角色之间是多对多关系,角色-权限之间是多对多关系:且用户和权限之间通过角色建立关系:在系统中验证时通过权限验证,角色只是权限集合,即所谓的显示角色:其实权限应该对应到资源 ...

  3. Han Xin and His Troops(扩展中国剩余定理 Python版)

    Han Xin and His Troops(扩展中国剩余定理 Python版) 题目来源:2019牛客暑期多校训练营(第十场) D - Han Xin and His Troops 题意:   看标 ...

  4. 第四篇:java读取Excel简单模板

    场景:对于经常需要导入Excel模板或数据来解析后加以应用的,使用频率非常之高,做了一个比较稳定的版本,体现在这些地方工具:org.apache.poi使用前必须了解这些:1.要解析,那肯定先判断是不 ...

  5. 3列滚动抽奖 jquery.slotmachine

    效果图: 需引入js文件: <script src="js/jquery-3.2.0.js"></script> <script src=" ...

  6. springboot-配置多数据源之番外篇(分包实现)

    场景: 随着业务发展,系统连接多数据库成为常态,继前面AOP的实现方式之后,这里记录一下分包实现的方式. 实现:  1.pom.xml <?xml version="1.0" ...

  7. 4_7.springboot2.x嵌入式servlet容器自动配置原理

    概述 Spring Boot对所支持的Servlet Web服务器实现做了建模抽象: Servlet容器类型  WebServer模型接口 WebServer工厂实现类 Tomcat    Tomca ...

  8. <Django> MVT三大块之Template(模板)

    1.模板简介 创建项目,基本配置 第一步:配置数据库 第二步:创建APP,配置APP 第三步:配置模板路径 第四步:配置分发urls.py(APP里面的) 根目录下,增加命名空间namespace,作 ...

  9. python基础语法(数据类型转换)

  10. vue2.0装jquery

    1.在项目目录下 cnpm install --save jquery 2.在webpack.base.conf.js中加入 var webpack = require('webpack') 3.在p ...