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. 框架进行时——SSM整合基础环境搭建

    一.导入相关的依赖 1 <!--打war包--> 2 <packaging>war</packaging> 3 4 <!--版本锁定--> 5 < ...

  2. python模块win32com中的early-bind与lazy-bind(以Autocad为例)

    1.什么是Lazy-bind模式,Early-bind模式? win32com中,Lazy-bind 模式指的是程序事先不知道对象的任何方法和属性,当对象属性,方法被调用时,程序才向对象发出一个询问( ...

  3. 后端程序员之路 22、RESTful API

    理解RESTful架构 - 阮一峰的网络日志http://www.ruanyifeng.com/blog/2011/09/restful.html RESTful API 设计指南 - 阮一峰的网络日 ...

  4. 微信小程序3D轮播图

    <!-- 轮播图 --> <swiper previous-margin='50px' next-margin='50px' bindchange="swiperChang ...

  5. LeetCode-二叉树的镜像

    二叉树的镜像 二叉树的镜像 给定一个二叉树,输出二叉树的镜像. 只需要使用一个简单的递归,分别对左右子树反转后再对当前结点进行反转. #include<iostream> #include ...

  6. redis基础:redis下载安装与配置,redis数据类型使用,redis常用指令,jedis使用,RDB和AOF持久化

    知识点梳理 课堂讲义 课程计划 1. REDIS 入 门 (了解) (操作)   2. 数据类型 (重点) (操作) (理解) 3. 常用指令   (操作)   4. Jedis (重点) (操作) ...

  7. PTA甲级—数学

    1.简单数学 1008 Elevator (20分) 模拟题 #include <cstdio> #include <cstring> #include <string& ...

  8. Python中OS对目录的操作以及引用

    路径的获取 对当前目录的获取 1 path = os.getcwd() 2 print("获取到的当前目录是:({})".format(path)) 获取当前文件所在的绝对路径 i ...

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

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

  10. 记一次 mysql主从复制安装配置 过程

    mysql主从复制安装配置 1.centos安装及准备 去centos官网下载相应source版本的镜像文件并在vmware中安装,安装中会遇到填写installation source,输入以下即可 ...