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

题意:

  找出女生的最高成绩和男生的最低成绩,并输出两者之差。

思路:

  模拟

Code:

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 struct Stu {
6 string name;
7 char gender;
8 string id;
9 int grade;
10 };
11
12 bool cmp1(Stu s1, Stu s2) { return s1.grade < s2.grade; }
13
14 bool cmp2(Stu s1, Stu s2) { return s1.grade > s2.grade; }
15
16 int main() {
17 int n;
18 cin >> n;
19 vector<Stu> male, female;
20 for (int i = 0; i < n; ++i) {
21 string name, id;
22 char gender;
23 int grade;
24 cin >> name >> gender >> id >> grade;
25 if (gender == 'F')
26 female.push_back({name, gender, id, grade});
27 else
28 male.push_back({name, gender, id, grade});
29 }
30 sort(female.begin(), female.end(), cmp2);
31 sort(male.begin(), male.end(), cmp1);
32 if (female.size() > 0)
33 cout << female[0].name << " " << female[0].id << endl;
34 else
35 cout << "Absent" << endl;
36 if (male.size() > 0)
37 cout << male[0].name << " " << male[0].id << endl;
38 else
39 cout << "Absent" << endl;
40 if (female.size() > 0 && male.size() > 0)
41 cout << female[0].grade - male[0].grade << endl;
42 else
43 cout << "NA" << endl;
44 return 0;
45 }

1036 Boys vs Girls的更多相关文章

  1. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  2. PAT 1036 Boys vs Girls[简单]

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  3. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  4. PAT 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

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

  6. 1036 Boys vs Girls (25分)(水)

    1036 Boys vs Girls (25分)   This time you are asked to tell the difference between the lowest grade o ...

  7. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  8. PATA 1036. Boys vs Girls (25)

    https://www.patest.cn/contests/pat-a-practise/1036 #include <bits/stdc++.h> using namespace st ...

  9. 1036. Boys vs Girls (25)

    #include <stdio.h>#include <string.h>int main(){ int n,i; while(scanf("%d",&am ...

  10. PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题

    题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...

随机推荐

  1. Socket实现简单聊天

    服务端: package main.java.com.socket_dome; import java.io.IOException; import java.io.InputStream; impo ...

  2. Docker 镜像加速教程

    原文链接:https://fuckcloudnative.io/posts/docker-registry-proxy/ 在使用 Docker 和 Kubernetes 时,我们经常需要访问 gcr. ...

  3. localforage indexedDB如何使用索引

    简单介绍下localForage.localForage 是一个 JavaScript 库,通过简单类似 localStorage API 的异步存储来改进你的 Web 应用程序的离线体验.它能存储多 ...

  4. AJAX 加载效果(遮盖层)

    //创建遮罩层函数体 function createMask(){ var node=document.createElement('div'); node.setAttribute('id','ba ...

  5. pytorch(01)环境配置及安装

    pytorch pytorch定位:深度学习框架 人工智能:多领域交叉科学技术 机器学习:计算机智能决策算法 深度学习:高效的机器学习算法 pytorch实现模型训练需要5个模块 数据 将数据从硬盘读 ...

  6. EF Core中通过Fluent API完成对表的配置

    EF Core中通过Fluent API完成对表的配置 设置实体在数据库中的表名 通过ToTable可以为数据模型在数据库中自定义表名,如果不配置,则表名为模型名的复数形式 public class ...

  7. 死磕生菜 -- lettuce 间歇性发生 RedisCommandTimeoutException 的深层原理及解决方案

    0x00 起源 项目的一些微服务集成了 Spring Data Redis,而底层的 Redis 客户端是 lettuce,这也是默认的客户端.微服务在某些环境中运行很正常,但在另一些环境中运行就会间 ...

  8. HDU_3359 Kind of a Blur 【浮点型高斯消元+BFS】

    一.题目 Kind of a Blur 二.分析 题目读起来挺费劲的. 主要就是要求一个矩阵,其中每个点及其于这个的曼哈顿距离小于D的点的值总和的平均值就是新生成的矩阵. 给定新生成的矩阵,求初始矩阵 ...

  9. 总结数据科学家常用的Python库

    概述 这篇文章中,我们挑选了24个用于数据科学的Python库. 这些库有着不同的数据科学功能,例如数据收集,数据清理,数据探索,建模等,接下来我们会分类介绍. 您觉得我们还应该包含哪些Python库 ...

  10. Cable Protection

    题目大意:求一颗基环树的最小点覆盖. 题解:其实是一道比较板子的树形dp,dp[i][0/1]表示取或者不取i点的最小点.但是首先我们要把基环树断开,然后分别考虑a被覆盖和b被覆盖的情况. dp[i] ...