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

题解:

#include"iostream"
#include "string"
#include<vector>
#include"algorithm"
#include "cmath"
using namespace std;

struct Student
{
string name;
char gender;
string id;
int grade;
};

bool malecmp(Student a, Student b)
{
return a.grade < b.grade;
}
bool femalecmp(Student a, Student b)
{
return a.grade > b.grade;
}
int main()
{
vector<Student> male;
vector<Student> female;
Student stu;
int num;
cin>>num;
for(int i=0;i<num;i++)
{
cin >> stu.name >> stu.gender >> stu.id >> stu.grade;
if(stu.gender == 'M')
male.push_back(stu);
else
female.push_back(stu);
}
sort(male.begin(),male.end(),malecmp);
sort(female.begin(),female.end(),femalecmp);
vector<Student>::iterator mit = male.begin();
vector<Student>::iterator fmit = female.begin();
if(fmit!=female.end())
{
cout<<(*fmit).name<<" "<<(*fmit).id<<endl;
}
else
cout<<"Absent"<<endl;
if(mit!=male.end())
{
cout<<(*mit).name<<" "<<(*mit).id<<endl;
}
else
cout<<"Absent"<<endl;
if(fmit==female.end()||mit==male.end())
cout<<"NA"<<endl;
else
cout<<(*fmit).grade-(*mit).grade<<endl;
return 0;
}


浙江大学Pat 1036 题解的更多相关文章

  1. 浙江大学 pat 1006题解

    1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  2. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. 浙江大学 pat 题解---58

    1058. A+B in Hogwarts (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue If you ...

  4. PAT 1031-1040 题解

    早期部分代码用 Java 实现.由于 PAT 虽然支持各种语言,但只有 C/C++标程来限定时间,许多题目用 Java 读入数据就已经超时,后来转投 C/C++.浏览全部代码:请戳 本文谨代表个人思路 ...

  5. pat甲级题解(更新到1013)

    1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...

  6. 浙江大学PAT上机题解析之5-05. QQ帐户的申请与登陆

    实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式说明: 输入首先给出一个正整数N(<=105),随后给出N行指令.每行指令的格式为:“命令符 ...

  7. 浙江大学PAT考试1069~1072(2013-11-2)

    11 题目地址:http://pat.zju.edu.cn/contests/pat-a-practise 1069: 由下降序和上升序两个四位数不断相减,然后得到新数据,始终会到达一个数字终止. 递 ...

  8. 浙江大学PAT考试1009~1012(1010上帝是冠军。。)

    哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...

  9. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

随机推荐

  1. servlet笔记

    开发servlet有三种方法: (1)    实现 Servlet接口 (2)    通过继承 GenericServlet (3)    通过继承 HttpServlet get提交和post提交的 ...

  2. Hololens Rest API

    通过Hololens提供的 Rest API 可以对Hololens进行远程控制和获取信息 ,可以通过第三方程序对Hololens重启或者关机,当然,还有更多更丰富的API,例如可以在PC上分流显示H ...

  3. 面向对象---final关键字

    final 在java中表示的意思是最终,也称为完结器,可以用final关键字声明类.属性.方法,在声明时需要注意以下几点: 1.使用final声明的类不能有子类. 2.使用final声明的方法不能被 ...

  4. HTML5 <canvas> 基础学习

    HTML5 <canvas> 元素用于图形的绘制,通过脚本 (通常是JavaScript)来完成. <canvas> 标签只是图形容器,您必须使用脚本来绘制图形 创建一个画布( ...

  5. ios下iphone的plus下

    二维码能被长按识别,但因为某种原因识别区域发生了偏移 meta标签定义了默认缩放为一倍就能识别,不定义就不能识别. 网上是这么说的: meta标签定义了默认缩放为一倍就能识别,不定义就不能识别.于是我 ...

  6. ES 6 : Math对象的扩展

    ES6在Math对象上新增了17个与数学相关的方法.所有这些方法都是静态方法,只能在Math对象上调用. 1.Math.trunc() Math.trunc方法用于去除一个数的小数部分,返回整数部分. ...

  7. JAVA-反射学习

    原文:http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html 个人总结: 1. 反射是什么:由字节码文件(.class)获取 ...

  8. [SOJ] DAG?

    Description 输入一个有向图,判断该图是否是有向无环图(Directed Acyclic Graph). Input 输入的第一行包含两个整数n和m,n是图的顶点数,m是边数.1<=n ...

  9. PWM

    #include "sys.h" #include "beep.h" //tim5 定时器 /* tim4 定时器 定时10分钟 控制LED1 */ void ...

  10. Openjudge-NOI题库-简单算术表达式求值

    题目描述 Description 两位正整数的简单算术运算(只考虑整数运算),算术运算为: +,加法运算:-,减法运算:*,乘法运算:/,整除运算:%,取余运算. 算术表达式的格式为(运算符前后可能有 ...