1036 Boys vs Girls (25)(25 point(s))
problem
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 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
tip
answer
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
struct P{
string name, gender;
int grade;
};
vector<P> lm, hf;
bool Comp(P a, P b){
return a.grade < b.grade;
}
int main(){
// freopen("test.txt", "r", stdin);
cin>>N;
string name, sex, gender;
int grade;
for(int i = 0; i < N; i++) {
cin>>name>>sex>>gender>>grade;
if(sex == "M"){
lm.push_back({name, gender, grade});
}else{
hf.push_back({name, gender, grade});
}
}
sort(lm.begin(), lm.end(), Comp);
sort(hf.begin(), hf.end(), Comp);
bool flag = true;
if(hf.size() == 0 || lm.size() == 0){
flag = false;
}
P woman, man;
if(hf.size()) {
woman = hf[hf.size()-1];
cout<<woman.name<<" " <<woman.gender<<endl;
}
else cout<<"Absent" <<endl;
if(lm.size()) {
man = lm[0];
cout<<man.name<<" "<<man.gender<<endl;
}
else cout<<"Absent" <<endl;
if(flag) cout<<woman.grade - man.grade<<endl;
else cout<<"NA" <<endl;
return 0;
}
experience
1036 Boys vs Girls (25)(25 point(s))的更多相关文章
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- 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 ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- 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[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- MySQL5.7.25(解压版)Windows下详细的安装过程
大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 【PAT】1020 Tree Traversals (25)(25 分)
1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
随机推荐
- Google Congestion Control介绍
随着网络带宽的日益增加和便携式设备,如智能手机或平板电脑处理能力的增强,基于互联网的实时通信已经成为热点. 虽然视频会议已商用了多年,特别是SKYPE这样的视频应用在互联网上已有10年时间,但针对实时 ...
- Python概念-迭代器的__iter__和__next__
大家都知道__iter__是可迭代对象和迭代器的独有方法,也知道__next__是迭代器的 既然已经学了面向对象了,那么如何自己写一个: 代码示例: # 编辑者:闫龙 class Range: def ...
- 查看 CUDA cudnn 版本
cuda 版本 cat /usr/local/cuda/version.txt cudnn 版本 cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MA ...
- Gitlab权限管理
使用管理员登陆gitlab(版本为8.9)创建一个组 给用户授权 创建新用户 再创建两个dev1和dev2 然后再到项目界面授权给pm授权master 创建库(事先先建一个java组) 设置权限 创建 ...
- Webmin试玩
安装: # cd /opt # wget http://www.webmin.com/jcameron-key.asc # wget http://www.webmin.com/download/rp ...
- SQLAlchemy-对象关系教程ORM-create
ORM是建立在SQL语言构造器之上的工具集,用于将Python对象映射到数据库的行,提供了一系列接口用于从数据库中存取对象(行).在ORM 工作时,在底层调用SQL语言构造器的API,这些通用的操作有 ...
- FFmpeg命令行工具和批处理脚本进行简单的音视频文件编辑
FFmpeg_Tutorial FFmpeg工具和sdk库的使用demo 一.使用FFmpeg命令行工具和批处理脚本进行简单的音视频文件编辑 1.基本介绍 对于每一个从事音视频技术开发的工程师,想必没 ...
- java基础81 jsp的内置对象(网页知识)
1.什么是内置对象? 在jsp开发中,会频繁使用到一些对象,如:HttpSession,ServletContext,HttpServletRequest. 如果每次使用这些对象时,都要去创 ...
- ioctl()函数获取本机IP、MAC
#include <sys/ioctl.h> int ioctl(int d, int request, ...); /* Socket configuration controls. * ...
- 洛谷P1972 HH的项链
传送门啦 分析: 题目描述不说了,大意是,求一段区间内不同元素的种数. 看到区间,我们大概先想到的是暴力(然后炸掉).线段树.树状数组.分块. 下面给出的是一种树状数组的想法. 首先,对于每一段区间里 ...