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))的更多相关文章

  1. 1036 Boys vs Girls (25 分)

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

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

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

  4. 1036 Boys vs Girls (25分)(水)

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

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

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

  6. PAT 1036 Boys vs Girls[简单]

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

  7. MySQL5.7.25(解压版)Windows下详细的安装过程

    大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...

  8. 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 ...

  9. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  10. 【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 ...

随机推荐

  1. Spark MLlib使用有感

    这些天在公司里面做文本分析的任务,我跟着玻哥一起做,先研究了算法的可行度,最后决定使用Google的Word2Vector和LDA算法来对文本进行分析.之前因为看过一些Spark的东西,所以准备瞄准M ...

  2. Python练习-无参装饰器的正确打开方式

    import time def DecoUserPrint(UserFunc):#定义一个DecoUserPrint接收参数的多重方法 def DecoPrint(): StartTime = tim ...

  3. linux学习记录.4.常用命令

    帮助command --help    获取‘command‘命令的帮助 目录与文件 cd /home    进入‘home’目录 cd ..    返回上一级目录 cd       进入个人目录 c ...

  4. 002_curl及postman专题

    一. 步骤 1: 下载cURL工具 使用您的Windows机器从cURL web站点下载最新版本的cURL: (1) 通常情况下,多数的Windows用户可以从官网下载页面http://curl.ha ...

  5. go语言项目汇总

    Horst Rutter edited this page 7 days ago · 529 revisions Indexes and search engines These sites prov ...

  6. Token机制,防止web页面重复提交

    1.业务要求:页面的数据只能被点击提交一次 2.发生原因: 由于重复点击或者网络重发,或者nginx重发等情况会导致数据被重复提交 3.解决办法: 集群环境:采用token加redis(redis单线 ...

  7. Python_oldboy_自动化运维之路_全栈考试(七)

    1. 计算100-300之间所有能被3和7整除的所有数之和 # -*- coding: UTF-8 -*- #blog:http://www.cnblogs.com/linux-chenyang/ c ...

  8. thinkphp5 IIS7.5 隐藏index.php的方法

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  9. caffe可视化

    1.画网络图 假    

  10. Es官方文档整理-2.分片内部原理

    Es官方文档整理-2.分片内部原理 1.集群      一个运行的Elasticsearch实例被称为一个节点,而集群是有一个或多个拥有相同claster.name配置的节点组成,他们共同承担数据和负 ...