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

题目分析:排序题 直接利用STL中sort来写 细心即可
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
struct student {
string name, gender, ID;
int grade;
};
bool compare(const student& a, const student& b)
{
return a.grade < b.grade;
}
int main()
{
vector<student> SM;
vector<student>SF;
int N;
cin >> N;
string name, gender, ID;
int grade;
for (int i = ; i < N; i++)
{
cin >> name >> gender >> ID >> grade;
if (gender == "M")
SM.push_back({ name,gender,ID,grade });
else
SF.push_back({ name,gender,ID,grade });
}
sort(SM.begin(), SM.end(), compare);
sort(SF.begin(), SF.end(), compare);
if (SF.size() == || SM.size() == )
{
if (SF.size() == )
{
cout << "Absent" << endl;
if (SM.size() == )
cout << "Absent" << endl;
else
cout << (*SM.begin()).name <<" "<<(*SM.begin()).ID<<endl;
}
else
{
cout << (*(SF.end() - )).name << " " << (*(SF.end() - )).ID << endl;
if(SM.size()==)
cout << "Absent" << endl;
}
cout << "NA";
}
else
{
cout << (*(SF.end() - )).name << " " << (*(SF.end() - )).ID << endl;
cout << (*SM.begin()).name << " " << (*SM.begin()).ID << endl;
cout << (*(SF.end() - )).grade - (*SM.begin()).grade;
}
}

最新文章

  1. 6种方法实现asp.net返回上一页
  2. JQuery mobile中按钮自定义属性的改变
  3. ng-bind的使用
  4. marathon参考(11):ports端口设置(转)
  5. CAD系统变量(参数)大全
  6. .Net的基础概念
  7. Android布局揭秘
  8. BNUOJ-26475 Cookie Selection 堆,线段树等
  9. Oracle EBS-SQL (BOM-14):检查工艺路线明细.sql
  10. JS实现时钟特效
  11. mpvue 小程序开发爬坑汇总
  12. Delegate与Event关系
  13. 在 Windows 中为高级用户配置 IPv6 的指南
  14. HashMap.put()和get()原理
  15. 百度开放平台连接MySQL数据库
  16. denyhost安装脚本
  17. Android-Start方式和Bind方式混合开启Service
  18. 第三百二十四节,web爬虫,scrapy模块介绍与使用
  19. sencha touch list 选择插件,可记忆已选项,可分组全选
  20. Mysql工作記錄之修改默認存儲引擎及重設root用戶密碼

热门文章

  1. Numpy之数据保存与读取
  2. 【Spring Data 系列学习】Spring Data JPA @Query 注解查询
  3. Simulink仿真入门到精通(十三) Simulink创建自定义库
  4. vue依赖注入
  5. Natas2 Writeup(水平越权)
  6. 从零开始学习R语言(二)——数据结构之“因素(Factor)”
  7. NIO的原理和文件读入读出及图片拷贝的使用
  8. Spring Controller单例与线程安全那些事儿
  9. hdu2087kmp模板练习
  10. springboot创建