1036 Boys vs Girls (25分)
 

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

题目分析:排序题 直接利用STL中sort来写 细心即可
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
struct student {
string name, gender, ID;
int grade;
};
bool compare(const student& a, const student& b)
{
return a.grade < b.grade;
}
int main()
{
vector<student> SM;
vector<student>SF;
int N;
cin >> N;
string name, gender, ID;
int grade;
for (int i = ; i < N; i++)
{
cin >> name >> gender >> ID >> grade;
if (gender == "M")
SM.push_back({ name,gender,ID,grade });
else
SF.push_back({ name,gender,ID,grade });
}
sort(SM.begin(), SM.end(), compare);
sort(SF.begin(), SF.end(), compare);
if (SF.size() == || SM.size() == )
{
if (SF.size() == )
{
cout << "Absent" << endl;
if (SM.size() == )
cout << "Absent" << endl;
else
cout << (*SM.begin()).name <<" "<<(*SM.begin()).ID<<endl;
}
else
{
cout << (*(SF.end() - )).name << " " << (*(SF.end() - )).ID << endl;
if(SM.size()==)
cout << "Absent" << endl;
}
cout << "NA";
}
else
{
cout << (*(SF.end() - )).name << " " << (*(SF.end() - )).ID << endl;
cout << (*SM.begin()).name << " " << (*SM.begin()).ID << endl;
cout << (*(SF.end() - )).grade - (*SM.begin()).grade;
}
}

1036 Boys vs Girls (25分)(水)的更多相关文章

  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 (25 分)

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

  3. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  4. PAT 1036 Boys vs Girls (25分) 比大小而已

    题目 This time you are asked to tell the difference between the lowest grade of all the male students ...

  5. 【PAT甲级】1036 Boys vs Girls (25 分)

    题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...

  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 (Advanced Level) Practice 1036 Boys vs Girls (25 分)

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  8. PATA 1036. Boys vs Girls (25)

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

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

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

随机推荐

  1. ubunto 免输入密码 登录 putty ssh-keygen

    交互式密码不安全,现在改用 ssh 证书方式,不用输入密码使用公钥证书登录. 方法1, 此方法,仅试用于,仅使用win putty 来连接方式使用,如果双方都是 linux 如 rsync 同步等时, ...

  2. MySQL数据库常用命令行整理(表格)

    Laplace Kang 2020-03-13T08:33:09Z 2020-03-14T17:35:53Z Sheet1 12480 9 600 600 6 9600 23040 0 0 600 0 ...

  3. ubuntu下使用apt-get install安装软件的安装位置

    在ubuntu下使用 apt-get install 或 apt install 下载安装软件,软件下载及安装后的目录.: A.下载的软件的存放位置:/var/cache/apt/archives B ...

  4. 2019计蒜客信息学提高组赛前膜你赛 #2(TooYoung,TooSimple,Sometimes Naive

    计蒜客\(2019CSP\)比赛第二场 巧妙爆零这场比赛(我连背包都不会了\(QWQ\) \(T1\) \(Too\) \(Young\) 大学选课真的是一件很苦恼的事呢! \(Marco\):&qu ...

  5. PowerShell初探

    Windows PowerShell是一种命令行外壳程序和脚本环境,它内置在每个受支持的Windows版本中(Windows 7/Windows 2008 R2和更高版本),使命令行用户和脚本编写者可 ...

  6. 一款带Web面板的轻量级、高性能内网穿透工具:nps使用教程

    说明:内网穿透工具之前已经介绍了不少了,比如Frp.lanproxy.Holer等,现在再介绍个带Web面板的穿透工具nps,之前叫easyProxy,只是改名了而已,该工具是一款使用go语言编写的轻 ...

  7. mybatis类型转换器 - 自定义全局转换enum

    在数据模型.接口参数等场景部分属性参数为一些常量值,比如性别:男.女.若是定义成int或String类型,于是类型本身的范围太宽,要求使用者需要了解底层的业务方可知如何传值,那整体来看增加沟通成本,对 ...

  8. 基于 HTML5 WebGL 的 智慧楼宇能源监控系统

    前言 21世纪,在能源危机和全球气候变暖的压力下,太阳能等可再生能源越来越受到关注,其中光伏建筑一体化逐渐成为绿色发展方式和生活方式,加强节能降耗,支持低碳产业和新能源.可再生能源发展,也已经成为国家 ...

  9. Android菜单(menu)

    Android  菜单 我们继续来进行学习,今天写一下在软件中用的还算较多的菜单. 1.Menu 菜单,很显然,作用就是点击不同的选项触发不同的方法.现在在安卓使用中推荐使用ActionBar,但这里 ...

  10. OpenCV-Python 读取显示视频 | 六

    目标 学习读取视频,显示视频和保存视频. 学习从相机捕捉并显示它. 你将学习以下功能:cv.VideoCapture(),cv.VideoWriter() 从相机中读取视频 通常情况下,我们必须用摄像 ...