PAT甲级——A1036 Boys vs Girls
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 <vector>
#include <algorithm>
#include <string>
using namespace std;
int N;
struct Node
{
string name, gender, ID;
int grade;
}node;
int main()
{
cin >> N;
vector<Node>male, female; //此代码是将数据保存下来排序,还可以直接在输入时就得到最高分和最低分,这样就大大节省了空间和时间
for (int i = ; i < N; ++i)
{
cin >> node.name >> node.gender >> node.ID >> node.grade;
if (node.gender == "M")
male.push_back(node);
else
female.push_back(node);
}
sort(male.begin(), male.end(), [](Node a, Node b) {return a.grade < b.grade; });
sort(female.begin(), female.end(), [](Node a, Node b) {return a.grade > b.grade; });
if (female.size() == )
cout << "Absent" << endl;
else
cout << female[].name << " " << female[].ID << endl;
if (male.size() == )
cout << "Absent" << endl;
else
cout << male[].name << " " << male[].ID << endl;
if (female.size() == || male.size() == )
cout << "NA" << endl;
else
cout << female[].grade - male[].grade << endl;
return ;
}
PAT甲级——A1036 Boys vs Girls的更多相关文章
- 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
1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...
- PAT 甲级 1036 Boys vs Girls(20)
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...
- PAT A1036 Boys vs Girls(25)
AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...
- A1036. Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- 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甲级: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[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
随机推荐
- Ubunto 无法连接ssh客服端
解决办法: (1)查看ip地址是否冲突 我在单位的虚拟机ip地址是192.168.14.85,与其它机器冲突了.改成了192.168.14.83 (2)关闭Ubuntu14.04的防火墙 root ...
- 在Laravel5.4中自动加载自定义文件
目标:想要在TestController.php中使用自定义的/app/Common/test.php中的test()函数. 1.在app文件夹下创建文件app/Common/test.php,文件内 ...
- day 51 阿里iconfont的使用
阿里iconfont的使用 1. 找到阿里巴巴图标库 2.找到图标 3.搜索你想要的图标 4.将图标添加到购物车 5.点击右上角的购物车按钮,我这里添加了两个. 6.提示你登陆,不需要花钱,找其中 ...
- 第八篇:ZTree操作总结
花了一个多星期,终于完成了这个完整的功能,今天周五是时候总结下加深理解了. 项目要实现的功能:将树形目录发布到发布库,若是根目录,没有发布,连同自己和下面所有的子目录们全部发布:不是根目录,判断父目录 ...
- SQL的语言分类
SQL的语言分类 DQL DQL(Data Query Language):数据查询语言 select DML DML(Data Manipulate Language):数据操作语言 insert ...
- appium + python 自动化调试手机时 UiAutomator exited unexpectedly with code 0, signal null
放上appium报错图,appium在手机里安装了appium setting 和unlock 软件,输入法也被变成了appium input ,但是就是点不到目标软件,手机也可以被cmd adb ...
- leetcode-105-从前序与中序遍历构造二叉树
题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.va ...
- Laravel移除Cache-Control
碰到一个问题,网站上线后,需要移除Cache-Control,就是下面这个东西 方案1 失败 参考网址:https://stackoverflow.com/questions/51821563/lar ...
- light oj 1095 组合数学
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...
- java使用stream流批量读取并合并文件,避免File相关类导致单文件过大造成的内存溢出。
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...