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
#include <iostream>
using namespace std;
struct stu{
string name;
char gender;
string id;
int grade;
};
int main()
{
int N;cin>>N;
bool male=false,female=false;
stu tmp,maleLowest,femaleHighest;
while(N--){
cin>>tmp.name>>tmp.gender>>tmp.id>>tmp.grade;
if(tmp.gender=='M'){
/**性别为M*/
if(male==false){
male=!male;
maleLowest=tmp;
}else{
if(maleLowest.grade>tmp.grade){
maleLowest=tmp;
}
}
}else{
/**性别为F*/
if(female==false){
female=!female;
femaleHighest=tmp;
}else{
if(femaleHighest.grade<tmp.grade){
femaleHighest=tmp;
}
}
}
}
/**output*/
if(female==false) cout<<"Absent"<<endl;
else cout<<femaleHighest.name<<" "<<femaleHighest.id<<endl;
if(male==false) cout<<"Absent"<<endl;
else cout<<maleLowest.name<<" "<<maleLowest.id<<endl;
if(male==false||female==false) cout<<"NA"<<endl;
else cout<<(femaleHighest.grade-maleLowest.grade)<<endl;
system("pause");
return ;
}
												

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

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

  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分) 比大小而已

    题目 This time you are asked to tell the difference between the lowest grade of all the male students ...

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

  7. 【PAT甲级】1036 Boys vs Girls (25 分)

    题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...

  8. PAT甲级——1036 Boys vs Girls

    1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...

  9. PAT (Advanced Level) 1036. Boys vs Girls (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. [ git ] eclipse如何与git 配合工作。

    原文链接http://blog.csdn.NET/yangzhihello/article/details/11003941 呵呵,看看这个吧.先去安装eclipse.然后在现在 egit,应该可以从 ...

  2. 基于代理的数据库分库分表框架 Mycat实践

    192.168.199.75 MySQL . MyCAT master 192.168.199.74 MySQL slave 192.168.199.76 MySQL standby master 如 ...

  3. LinkedList Stack

  4. container_of宏解析 && 为什么需要使用中间变量__mptr?

    #define container_of(ptr, type, member) ({ \ )->member ) *__mptr = (ptr); \ (type *)( (char *)__m ...

  5. Putty - 免用户名密码登录

    打开 Putty 时携带 -pw your_password your_username@your_host 参数即可.

  6. rocketMQ 通信协议格式

    rocketMQ 使用 netty 通信,端对端的通信,为了避免粘包.分包,需要指定发送数据的边界. 使用的解码器是 LengthFieldBasedFrameDecoder // org.apach ...

  7. VS2012下std::function的BUG解决办法

    VS2012版本下std::function存在问题,链接:https://stackoverflow.com/questions/13096162/stdfunction-not-compiling ...

  8. maven scope provided和runtime的例子

    maven常用的scope有compile,provided,runtime,test. complie是默认值,表示在build,test,runtime阶段的classpath下都有依赖关系.te ...

  9. vim加脚本注释和文本加密

    vim /etc/vimrc 一.李导版本 autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" fun ...

  10. Spring Security Session Time Out

    最近在用Spring Security做登录管理,登陆成功后,页面长时间无操作,超过session的有效期后,再次点击页面操作,页面无反应,需重新登录后才可正常使用系统. 为了优化用户体验,使得在se ...