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. 如何清除本机DNS缓存

    如何清除本机DNS缓存 在实际应用过程中可能会遇到DNS解析错误的问题,就是说当我们访问一个域名时无法完成将其 解析到IP地址的工作,而直接输入网站IP却可以正常访问,这就是因为DNS解析出现故障造成 ...

  2. iOS疑问

    1.__NSFrozenDictionaryM在数组类簇中是什么角色?

  3. JS switch 分支语句

    描述:根据一个变量的不同取值,来执行不同的代码. 语法结构: switch(变量) { case 值1: 代码1; break; case 值2: 代码2; break; case 值3: 代码3; ...

  4. STL容器set用法以及codeforces 685B

    以前没怎么用过set,然后挂训练赛的时候发现set的妙用,结合网上用法一边学一边写. 首先set是一种容器,可以跟其他STL容器一样用 set<int > s 来定义, 它包含在STL头文 ...

  5. JVM系列(三)— Java内存模型

    我们已经了解了Java虚拟机的运行时数据区,垃圾收集相关知识,接下来学习虚拟机非常重要的部分 这就是Java内存模型与线程(第12章),这一篇,将主要讲讲内存模型 了解Java内存模型之前,先了解下计 ...

  6. shell脚本练习04

    ######################################################################### # File Name: -.sh # Author ...

  7. 使用CEfSharp之旅(5)CEFSharp 隔离Cookie

    原文:使用CEfSharp之旅(5)CEFSharp 隔离Cookie 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https:/ ...

  8. Java开发系列-注解

    概述 在JDK5之后提供了一个新特性,和类.接口同级.定义时使用的关键字是@interface.注解主要有三个作用,分别是编译检查.替代配置文件.定义注解(元注解).分析代码(用到反射).注解的本质就 ...

  9. C++: Basic knowledge Part 1

    1.在 C++ 程序中调用被 C 编译器编译后的函数,为什么要加 extern “C”? 首先,extern 是 C/C++ 语言中表明函数和全局变量作用范围的关键字,该关键字告诉编译器,其声明的函数 ...

  10. [JZOJ4684] 【GDOI2017模拟8.11】卡牌游戏

    题目 描述 题目大意 有111到2n2n2n牌,一开始分别给两个人,每人nnn张. 轮流出牌,给出对手出牌的顺序,若自己的牌更大,就记一分. 在中间的某个时刻可以改变游戏规则. 问最大的分数. 思考历 ...