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. Svelte 极简入门

    ​弹指之间即可完成.   注意:原文发表于 2017-8-7,随着框架不断演进,部分内容可能已不适用.     Svelte 是一种新型框架.   以往我们要引入一个框架或者类库,可以通过在页面上放置 ...

  2. Hexo一键部署到阿里云OSS并设置浏览器缓存

    自建博客地址:https://bytelife.net,欢迎访问! 本文为博客自动同步文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://bytel ...

  3. 后端程序员之路 37、Akka、Actor、Scala初窥

    Akkahttp://akka.io/ Akka 是一个用 Scala 编写的库,用于简化编写容错的.高可伸缩性的 Java 和 Scala 的 Actor 模型应用,是一个广泛运用的分布式应用框架. ...

  4. Java 基础加强 02

    基础加强·反射 和 枚举 类的加载概述和加载时机 * A:类的加载概述 * 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载.连接.初始化来实现对这个类的初始化 * 加载 * 就是指 ...

  5. struct2中package的参数解析

    struct2框架的核心组件是action和拦截器,它使用包来管理action和拦截器,每个包就是多个action.多个拦截器引用的集合.在struct.xml中,package元素用于定义包的配置, ...

  6. Jmeter +Jenkins +Ant 集成发送邮件报告

    [TOC] 一.什么是接口测试? 接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.测试的重点是要检查数据的交换,传递和控制管理过程,以及系 ...

  7. TIOBE 编程语言排行榜

    https://www.tiobe.com/tiobe-index/ TIOBE 编程语言排行榜是编程语言流行趋势的一个指标

  8. 微信小程序Animation动画的使用

    目录 1,前言 2,属性 3,使用 1,前言 和css3动画不同,小程序中动画是主要是通过js控制的,简单来说就是创建一个动画实例animation.调用实例的方法来定义动画效果.最后通过动画实例的e ...

  9. CRC校验原理和verilog实现方法(一)

    1.CRC简介 CRC全称循环冗余校验(Cyclic Redundancy Check, CRC),是通信领域数据传输技术中常用的检错方法,用于保证数据传输的可靠性.网上有关这方面的博客和资料很多,本 ...

  10. LAMP环境搭建与配置

    下载mysql 解压 运行错误 下载插件 启动成功 安装Apache 解压 报错  安装插件 再次报错 修改文档 成功 安装插件 下载 安装php 安装完成 解析php 安装完成 虚拟主机(共享主机, ...