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 ...
随机推荐
- 20155336 2016-2017-2《JAVA程序设计》第五周学习总结
20155336 2016-2017-2<JAVA程序设计>第五周学习总结 教材学习内容总结 第八章 语法与继承构架 使用try.catch 特点: 使用try.catch语法,JVM会尝 ...
- Linux服务-配置Nginx反向代理
任务目标:实现基于轮询的方式调度三台web,并验证结果:实现基于权重的方式调度三台web,并验证结果:实现基于hash的方式调用三台web,并验证结果 由于刚刚做了nfs设置,为了提现实验结果,我在w ...
- spring-boot-全局异常
Spring Boot默认的异常处理机制 默认情况下,Spring Boot为两种情况提供了不同的响应方式. 一种是浏览器客户端请求一个不存在的页面或服务端处理发生异常时,一般情况下浏览器默认发送的请 ...
- java所搜引擎slor学习笔记(一)
java搜索引擎有很多,比较熟悉的就是slor和lucene. luncene: 概念:全文检索是计算机程序通过扫描文章中的每一个词,对每一个词建立一个索引,指明该词在文章中出现的次数和位置.当用户查 ...
- Java中关于变量的几种情况
Java中关于变量的几种情况 1.继承时变量的引用关系 class Animals { int age = 10; void enjoy() { System.out.println("An ...
- elasticsearch-head插件安装的一些坑!es6.5.4版本
折腾了一晚上,总算成功了!,大部分坑都记录了下来,版本升级太快真实个大坑,每个版本都不一样,学的心累!! 这坑太多了!主要就是以下几点最主要的: 因为我这里只使用hear安装,不使用哪个打包工具,所以 ...
- Centos7安装 mysql5.6.29 shell脚本
有很多可以借鉴的地方,故转载: 创建脚本mysql.sh,直接运行sh mysql.sh !/bin/bash if [ -d /software ] ;then cd /software else ...
- DRM/KMS 基本组件介绍
Each DRM device provides access to manage which monitors and displays are currently used and what fr ...
- Intel大坑之一:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 最近在写一些字符串函数的优化,兴趣使然,可是写的过程中,想要实现 128bit 的按 bit 逻辑位移,遇到了一个大坑,且听我娓娓道来. 如果要追究标题,更确切的是丢失的SSE2 128 bit ...
- java基础38 正则表达式
1.常用的正则表达式 预定义字符类:. 任何字符(与行结束符可能匹配也可能不匹配) \d 数字:[0-9] \D 非数字: [^0-9] \s 空白字符:[ \t\n\x0B\f\r] \S ...