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