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;
}
}
1036 Boys vs Girls (25分)(水)的更多相关文章
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT 1036 Boys vs Girls (25分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- 【PAT甲级】1036 Boys vs Girls (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- PAT Advanced 1036 Boys vs Girls (25 分)
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PAT (Advanced Level) Practice 1036 Boys vs Girls (25 分)
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PATA 1036. Boys vs Girls (25)
https://www.patest.cn/contests/pat-a-practise/1036 #include <bits/stdc++.h> using namespace st ...
- PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
随机推荐
- codeigniter框架的使用感受和注意事项
codeigniter是一个轻量级的php的web框架,今年2月22日,正式发布了4.0版本.简称CI框架 先使用了CI的3.15版,基本上是不用安装,把框架文件放到web目录下,让后通过简单的配置, ...
- 纯C 实现 strpos substr strspilt str_trim
在C 语言中没有C++ 好用的 spilt 方法 (STL 带的也不怎么好用) #include <stdio.h> #include <string.h> #include ...
- activated钩子函数
activated钩子函数是在组件被激活后的钩子函数,mounted是不保证组件在document中,也就是组件还没有被激活,因此可以理解为activated执行在mounted之后. 在跳转传值时, ...
- python基础学习day4
列表的初识 why:int bool str str: 存储少量的数据. str:切片还是对其进行任何操作,获取的内容全都是str类型.存储的数据单一. what:list list = [66, ' ...
- [Alg] 文本匹配-单模匹配与多模匹配
实际场景: 网站的用户发了一些帖子S1, S2,...,网站就要审核一下这些帖子里有没有敏感词. 1. 如果网站想查一下帖子里有没有一个敏感词P,这个文本匹配要怎么做更快? 2. 如果网站想查一下帖子 ...
- 推荐三款好用的JSON格式化工具——JSON-handle & HiJson & JSTool
工具一:JSON-handle JSON-Handle是一款谷歌浏览器插件. 1.访问http://jsonhandle.sinaapp.com/下载 2.打开Chrome浏览器的扩展程序(访问chr ...
- Redis源码分析: String(SDS)容量调整分析
整体思路: 1 惰性缩容.不释放空间,留给到期释放等机制释放. 2 加倍扩容.在需要空间达1M之前按新空间两倍分配空间,否则按新空间大小+1M分配.注意,1M=1024*1024*Char.Char可 ...
- hdu1226超级密码 bfs
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1226/ 题目大意是:寻找一个五百位之内的C进制密码,该密码是N的正整数倍,而且只能用给定的数构成密码,求这样的密 ...
- 第十周Java实验作业
实验十 泛型程序设计技术 实验时间 2018-11-1 1.实验目的与要求 (1) 理解泛型概念: 泛型:也称参数化类型,就是在定义类,接口和方法时,通过类型参数只是将要处理的类型对象.(如Arra ...
- wr720n v4 折腾笔记(二):刷入不死Uboot
0x01 前言 接着上节刷入Openwrt开始说起,此次开始刷入不死Uboot,刷入之后就可以在Uboot里面随便刷机,再也不怕成砖了. 固件附件地址: 下载地址1(还是之前一的包) flash文件地 ...