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. Kubernetes中分布式存储Rook-Ceph的使用:一个ASP.NET Core MVC的案例

    在<Kubernetes中分布式存储Rook-Ceph部署快速演练>文章中,我快速介绍了Kubernetes中分布式存储Rook-Ceph的部署过程,这里介绍如何在部署于Kubernete ...

  2. HTTP 请求URL中不能含有空格

    如果含有空格 会报 不合法参数异常 正确做法是将其encode URLEncoder.encode(targetString, "utf-8").replaceAll(" ...

  3. docker方式部署禅道

    一.概述 使用docker方式部署禅道简单,快速,不容易出错.比起编译安装要方便很多. 二.部署 环境说明 操作系统:centos 7.6 ip地址:10.212.82.65 docker版本:19. ...

  4. void指针及指针的多次赋值的理解

    1.void指针的类型转换 int A::functionCommamd(const DWORD _from,const DWORD _to,const DWORD Event_type,void * ...

  5. es6 快速入门 系列 —— 变量声明:let和const

    其他章节请看: es6 快速入门 系列 变量声明:let和const 试图解决的问题 经典的 var 声明让人迷惑 function demo1(v){ if(v){ var color='red' ...

  6. CCF(317号子任务)-35分:Dijikstra算法

    317号子任务 201903-5 为了过前60分,想使用dijikstra优化算法的,但是最后还是只过了35分.这里的思路只需要先将所有的行星据点进行一次dijikstra,分别存储所有点到行星的最短 ...

  7. Slenium详解

    Slenium介绍 Selenium 是一个 Web 应用的自动化框架. 通过它,我们可以写出自动化程序,像人一样在浏览器里操作web界面. 比如点击界面按钮,在文本框中输入文字 等操作. 而且还能从 ...

  8. 2020年12月-第01阶段-前端基础-认识WEB

    认识WEB 1.认识网页 网页主要由文字.图像和超链接等元素构成.当然,除了这些元素,网页中还可以包含音频.视频以及Flash等. 思考: 网页是如何形成的呢? 总结 网页有图片.链接.文字等元素组成 ...

  9. 漏洞复现-Discuz-命令执行(wooyun-2010-080723)

            0x00 实验环境 攻击机:win10 靶机:Ubuntu18 (docker搭建的vulhub靶场) 0x01 影响版本 Discuz 7.x 6.x版本 0x02 实验目的 学习d ...

  10. go中sync.Once源码解读

    sync.Once 前言 sync.Once的作用 实现原理 总结 sync.Once 前言 本次的代码是基于go version go1.13.15 darwin/amd64 sync.Once的作 ...