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 name, gender, ID 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 gradeF−gradeM. 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分)(水)的更多相关文章
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT 1036 Boys vs Girls (25分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- 【PAT甲级】1036 Boys vs Girls (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- 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 ...
- 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 ...
- PATA 1036. Boys vs Girls (25)
https://www.patest.cn/contests/pat-a-practise/1036 #include <bits/stdc++.h> using namespace st ...
- PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
随机推荐
- .NET写入文件操作
2018-01-16 22:44:35 许多程序需要记录运行日志,这就需要将程序运行记录写入本机,一般是.txt 文本或.csv 文件.具体操作如下: 一.C# using System.IO; ...
- 一个和与后台数据连接的模板get post put 以及延伸的query
/* example: require.config({ paths: { "httpClient": "../../core/http-client" } } ...
- 03.文件I/O
UNIX系统中的大多数文件I/O只需用到5个函数:open.read.write.lseek和close. 本章所说明的函数称为不带缓冲的I/O.不带缓冲指的是每个read和write都调用内核中的一 ...
- HTML每日学习笔记(0)
2019.7.14 1.属性为 HTML 元素提供附加信息,总是在 HTML 元素的开始标签中规定. 例子:<h1 align="center"> 对齐方式 <b ...
- 同网页的WebRTC实现与源码分析
基本按照Real time communication with WebRTC搭建(下面简称该网站为官方tutorial) 本文重视WebRTC的基于同页面通信的代码实现,主要讲述顺序是WebRTC的 ...
- MyBatis框架——动态SQL
MyBatis 作为⼀个“半⾃动化”的 ORM 框架,需要开发者⼿动定义 SQL 语句. 在业务需求⽐较复杂的情 况下,⼿动拼接 SQL 语句的⼯作量会⾮常⼤,为了适⽤于不同的业务需求,往往需要做很多 ...
- Blazor-断开连接后重新加载浏览器
在大多数情况下,Blazor将与以前相同的线路上重新连接到服务器.但有时无法重新连接,需要重新加载web浏览器才能使网站重新工作.如果服务器回收应用程序池,则需要手动重新加载页面在没有调试的情况下在I ...
- Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of diosgenin against cerebral ischemia reperfusion effects(大脑的定量蛋白质组学揭示了薯蓣皂苷元对脑缺血再灌注效应的分子机制)
文献名:Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of dios ...
- jenkins-gitlab-harbor-ceph基于Kubernetes的CI/CD运用(一)
注:这部分的学习还是要靠自己多点点 多尝试尝试 这部分19年3月份我是玩的很溜的,一年没用,基本忘光光了. 学习要温故而知新! 流程拓扑图 前提准备 部署应用服务 部署kubernetes 集群:ht ...
- CTF_WriteUp_HTTP——302临时重定向问题
HTTP--302临时重定向 题目描述 点击给出的链接后,没有发生任何变化. 解决方案 通过擦好看网络请求,可以发现发生了302临时跳转,所以我们无法通过浏览器直接访问未跳转的页面,而flag 可能藏 ...