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

题意:

  找出女生的最高成绩和男生的最低成绩,并输出两者之差。

思路:

  模拟

Code:

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 struct Stu {
6 string name;
7 char gender;
8 string id;
9 int grade;
10 };
11
12 bool cmp1(Stu s1, Stu s2) { return s1.grade < s2.grade; }
13
14 bool cmp2(Stu s1, Stu s2) { return s1.grade > s2.grade; }
15
16 int main() {
17 int n;
18 cin >> n;
19 vector<Stu> male, female;
20 for (int i = 0; i < n; ++i) {
21 string name, id;
22 char gender;
23 int grade;
24 cin >> name >> gender >> id >> grade;
25 if (gender == 'F')
26 female.push_back({name, gender, id, grade});
27 else
28 male.push_back({name, gender, id, grade});
29 }
30 sort(female.begin(), female.end(), cmp2);
31 sort(male.begin(), male.end(), cmp1);
32 if (female.size() > 0)
33 cout << female[0].name << " " << female[0].id << endl;
34 else
35 cout << "Absent" << endl;
36 if (male.size() > 0)
37 cout << male[0].name << " " << male[0].id << endl;
38 else
39 cout << "Absent" << endl;
40 if (female.size() > 0 && male.size() > 0)
41 cout << female[0].grade - male[0].grade << endl;
42 else
43 cout << "NA" << endl;
44 return 0;
45 }

1036 Boys vs Girls的更多相关文章

  1. 1036 Boys vs Girls (25 分)

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

  2. PAT 1036 Boys vs Girls[简单]

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

  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. PAT 1036 Boys vs Girls (25 分)

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

  5. 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 ...

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

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

  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. PATA 1036. Boys vs Girls (25)

    https://www.patest.cn/contests/pat-a-practise/1036 #include <bits/stdc++.h> using namespace st ...

  9. 1036. Boys vs Girls (25)

    #include <stdio.h>#include <string.h>int main(){ int n,i; while(scanf("%d",&am ...

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

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

随机推荐

  1. R语言学习4:函数,流程控制,数据框重塑

    本系列是一个新的系列,在此系列中,我将和大家共同学习R语言.由于我对R语言的了解也甚少,所以本系列更多以一个学习者的视角来完成. 参考教材:<R语言实战>第二版(Robert I.Kaba ...

  2. Win命令行切换Python版本

    目录 安装2.x 和 3.x 的python 设置系统环境变量 pip的使用 参考 安装2.x 和 3.x 的python 我这里使用anaconda来安装两个版本的python包. conda cr ...

  3. PAT-1119(Pre- and Post-order Traversals)+前序和后序遍历确定二叉树+判断二叉树是否唯一

    Pre- and Post-order Traversals PAT-1119 这题难度较大,主要需要考虑如何实现根据前序遍历和后序遍历来确定一颗二叉树 一篇好的文章: 题解 import java. ...

  4. HDOJ-1754(线段树+单点更新)

    I Hate It HDOJ-1754 这道题是线段树简单的入门题,只是简单考察了线段树的基本使用,建树等操作. 这里需要注意的是输入要不使用scanf要不使用快速输入. 这里的maxs数组需要开大一 ...

  5. SnowNLP——获取关键词(keywords(1))

    一.SnowNLP的获取文本关键词 前面介绍了SnowNLP的获取关键词的方法,这里再重现一下 1 from snownlp import SnowNLP 2 # 提取文本关键词,总结3个关键词 3 ...

  6. 追溯 MySQL Statement Cancellation Timer

    原文 1. 背景 在 jstack 的内容中可以看到以下的 MySQL Statement Cancellation Timer 守护线程, 在业务高峰期的时候会出现大量的这类守护线程, 由此追溯该线 ...

  7. ubuntu18.04+gunicorn+nginx+supervisor+mysql+redis安装django项目

    Ubuntu18.04 install Django project 项目准备: ECS 实例 (云服务器) 此安装部署方案适合本地ubuntu18.04系统安装和虚拟机中ubuntu18.04系统安 ...

  8. hibernate 的一对多关联关系映射配置

    hibernate 是操作实体类: 表是一对多的关系,当创建这2个实体的时候 在一的一方定义一个多的一方的集合 在多的一方定义一个一的一方的对象 表是多对多的关系,当创建这2个实体的时候 在互相中都有 ...

  9. BZOJ_4034 [HAOI2015]树上操作 【树链剖分dfs序+线段树】

    一 题目 [HAOI2015]树上操作 二 分析 树链剖分的题,这里主要用到了$dfs$序,这题比较简单的就是不用求$lca$. 1.和树链剖分一样,先用邻接链表建双向图. 2.跑两遍$dfs$,其实 ...

  10. Just a Joke HDU - 4969(物理+积分)

    题目链接:https://vjudge.net/problem/HDU-4969#author=0 题意:一个人在圆心以V2速度追赶一个以V1的速度进行圆周运动,问在圆心的人能否在不超过D的距离追上他 ...