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. LeetCode 476. Number Complement

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  2. Objective-C Runtime 运行时之六:拾遗(转载)

    前面几篇基本介绍了runtime中的大部分功能,包括对类与对象.成员变量与属性.方法与消息.分类与协议的处理.runtime大部分的功能都是围绕这几点来实现的. 本章的内容并不算重点,主要针对前文中对 ...

  3. CSS3之3D效果中的transform运用

    css3中添加了很多新的标签 属性 描述 css transform 向元素应用 2D 或 3D 转换. 3 transform-origin 允许你改变被转换元素的位置. 3 transform-s ...

  4. python字符串和列表

    import sys#sys.argv[0] 被设定为指定模块的全名#脚本名和附加参数传入一个名为 sys.argv 的字符串列表.你能够获取这个列表通过执行 import sys,列表的长度大于等于 ...

  5. 解决Intellij Idea里tomcat启动报The JRE_HOME environment variable is not defined correctly的错误

    创建一个maven项目后想启动tomcat测试一下新建的maven项目,结果一直报The JRE_HOME environment variable is not defined correctly, ...

  6. 获取Java的32位MD5实现

    获取Java的32位MD5实现 public static String md5(String s) { char hexDigits[] = {'0','1','2','3','4','5','6' ...

  7. Number Sequence (HDU 1711)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. awk学习笔记二:调用shell、文件执行(转)

    awk 'BEGIN {print "Hello"}' 不操作文件直接处理数据流 要调用shell则可以用管道命令 如,打印日期awk 'BEGIN {"date&quo ...

  9. jquery点击目标DIV以外关闭效果

    $(function(){ $(".cover").hide(); $("#call").click(function(){ console.log(" ...

  10. R安装

    linux: 在编译R之前,需要通过yum安装以下几个程序: #yum install gcc-gfortran              #否则报”configure: error: No F77 ...