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. Could not locate executable E:\SoftWave\Hadoop-2.2.0\bin\winutils.exe in the Hadoop binaries解决办法

    需要下载windows版本 bin目录下的文件,替换hadoop目录下原来的bin目录下的文件.下载网址是: https://github.com/srccodes/hadoop-common-2.2 ...

  2. Android Tips

    (1).设置图片缓存大小,一般可以设置为内存的1/8 int memoryCache = (int) (Runtime.getRuntime().maxMemory() / 8); (2). (3). ...

  3. js分页模板

    /** *参数说明: *currentPage:当前页数 *countPage:总页数 *changeMethod:执行java后台代码的js函数,即是改变分页数据的js函数 */ function  ...

  4. CentOS网络接口配置文件ifcfg-eth详解

    ======CentOS网络接口配置文件ifcfg-eth详解====== 文件 /etc/sysconfig/network-scripts/ifcfg-eth0在/etc/sysconfig/ne ...

  5. hdu1033

    #include<stdio.h> #include<string.h> const int MAXN=200; char str[MAXN]; int main() { in ...

  6. iOS10 CAAnimationDelegate的适配

    最近在xcode8打开之前的动画代码,看到如下警告

  7. Ubuntu14.04浏览器Firefox安装flash播放插件

    sudo apt-get update sudo apt-get install flashplugin-nonfree ================= 类飞秋软件 sudo apt-get in ...

  8. 史上最详细SharePoint 2013安装步骤图解新手教程

    来源:// http://www.itexamprep.com/cn/microsoft/soft/sharepoint2013/2013/0408/2866.html 文章就是SharePoint2 ...

  9. spring mvc 实现文件上传下载

    /** * 文件上传 * @param pictureFile */ @RequestMapping("/reportupload") public ResponseInfo up ...

  10. Selenium+Python之163邮件发送

    今晚写了一个163邮箱登录的脚本,由于不停的访问163登录主页导致直接访问163邮箱主页登录需要输入验证码,因为无法获取到验证码,就这导致直接访问主页登录脚本不可行,为了绕过验证码,现在先访问hao1 ...