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. django 博客搭建

    comment1.安装django pip install django 2.创建项目 django-admin startproject mysite 3.在mysite文件夹下创建app pyth ...

  2. 【MySQL】Docker搭建MySQL8.0

    目录 Docker搭建MySQL8.0 目的: 1.安装Docker 2.查看docker镜像 3.拉取mysql官方镜像 4. 查看目前的镜像 5.运行docker mysql镜像 6.查看目前运行 ...

  3. vscode在执行 npm任务的时候,会先执行package的name@version 然后命令名 加 当前路径,问题是我的引入路径e是小写的,会导致调试错误,解决方案:没找到,先手书吧

    vscode在执行 npm任务的时候,会先执行package的name@version 然后命令名 加 当前路径,问题是我的引入路径e是小写的,会导致调试错误,解决方案:没找到 Executing t ...

  4. Requests发送带cookies请求

    一.缘 起 最近学习[悠悠课堂]的接口自动化教程,文中提到Requests发送带cookies请求的方法,笔者随之也将其用于手头实际项目中,大致如下 二.背 景 实际需求是监控平台侧下发消息有无异常, ...

  5. kerberos系列之hdfs&yarn认证配置

    一.安装hadoop 1.解压安装包重命名安装目录 [root@cluster2_host1 data]# tar -zxvf hadoop-2.7.1.tar.gz -C /usr/local/ [ ...

  6. 基于 websocket 的多端桥接平台

    我们现在的业务是基于新闻客户端实现的,都要经过新闻客户端的环境,进行前后端数据上的交互.但是我们在调试过程中,非常的不方便. 通常使用的工具有:modheader, postman, fiddler ...

  7. OFD电子证照模版制作工具使用说明

    每一类电子证照都具有相同板式,不同的电子证照之间只是文字.图片的差异.生成电子证照常用的方式就是采用模版批量生成. 本软件可以方便的设计证照模版.服务端根据模版生成电子证照,不同种类的电子证照生成逻辑 ...

  8. hdu1548 奇怪的电梯 dfs dijkstra bfs都可以,在此奉上dfs

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/5706/ 简单的规定深度进行搜索,代码如下: #include<bits/stdc++.h> usin ...

  9. CF1326A Bad Ugly Numbers 题解

    原题链接 简要题意: 构造一个长为 \(n\) 的数,使得每位均不为 \(0\),且 \(n\) 不被它的各位数字整除. 比方说, \(n = 239\) 是合法的.因为: \(2 \not | 23 ...

  10. 动态规划-01背包-Tallest Billboard

    2020-02-07 17:46:32 问题描述: 问题求解: 解法一:BF 看问题规模看似可以直接暴力解决. 如果直接去解肯定是会超时的,因为每次将原空间划分成A区域,B区域和剩余区域的时间复杂度为 ...