题目

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

题目解读

给出 N 个学生信息,名字、性别(M/F)、ID、分数,找到女生中分数最高的那个人,输出她的 名字 ID,如果不存在就输出 Absent;找到男生中分数最低的那个,输出他的名字 ID,如果不存在就输出 Absent;如果女生最高分和男生最低分都存在就输出 二者之差(女生最高分-男生最低分),如果任何一个不存在就输出 NA

思路分析

不知道这个题目为什么会有25分,感觉就是比比大小。

  • 四个变量分别保存女生最低分(初始化为-1)、这个女生(name ID)、男生最低分(初始化为101)、这个男生(name ID),每次读入一个学生信息,如果是女生就去比较更新女生最高分和对应的女生,否则就去比较更新男生最低分和对应的男生。
  • 如果女生最高分是-1,就输出 Absent,否则输出这个最高分女生的name ID
  • 如果男生最低分是101,就输出 Absent,否则输出这个最低分男生的name ID
  • 如果二者都存在就输出最高分-最低分,否则输出 NA

代码

#include <iostream>
using namespace std; int main() {
int n;
// 找女生最高分和男生最低分
string female, male;
int femalegrade = -1, malegrade = 101;
cin >> n;
while (n-- > 0) {
string name, sex, id;
int grade;
cin >> name >> sex >> id >> grade;
// 是女生
if (sex == "F") {
// 找女生最高分
if (grade > femalegrade) {
femalegrade = grade;
female = name + " " + id;
}
// 找男生最低分
} else if (grade < malegrade) {
malegrade = grade;
male = name + " " + id;
}
}
// 输出女生最高分,不存在输出 Absent
if (femalegrade == -1) cout << "Absent" << endl;
else cout << female << endl;
// 输出男生最低分,不存在输出 Absent
if (malegrade == 101) cout << "Absent" << endl;
else cout << male << endl;
// 输出二者之差,如果有一个不存在输出 NA
if (femalegrade != -1 && malegrade != 101) cout << femalegrade - malegrade;
else cout << "NA"; return 0;
}

PAT 1036 Boys vs Girls (25分) 比大小而已的更多相关文章

  1. PAT 1036 Boys vs Girls (25 分)

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

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

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

  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. 1036 Boys vs Girls (25分)(水)

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

  5. 【PAT甲级】1036 Boys vs Girls (25 分)

    题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...

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

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

  8. PAT 1036 Boys vs Girls[简单]

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

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

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

随机推荐

  1. A. A Twisty Movement dp

    https://codeforces.com/problemset/problem/933/A 这个是一个dp,但是我并没有看出来,然后也不太会写, 这种题一般应该要想到先预处理前缀和后缀,然后再进行 ...

  2. Blazor入门:ASP.NET Core Razor 组件

    目录 关于组件 组件类 静态资产 路由与路由参数 组件参数 请勿创建会写入其自己的组参数属性的组件 子内容 属性展开 任意参数 捕获对组件的引用 在外部调用组件方法以更新状态 使用 @ 键控制是否保留 ...

  3. vue省市区三级联动(高仿京东)

    该栗子是我直接从公司的项目单独拉出来的(懒得重新写一次了),所以代码会有些冗余,下面直接看效果: 接着上代码: html: <template> <div> <div c ...

  4. JUC之ReentrantLock源码分析

    ReentrantLock:实现了Lock接口,是一个可重入锁,并且支持线程公平竞争和非公平竞争两种模式,默认情况下是非公平模式.ReentrantLock算是synchronized的补充和替代方案 ...

  5. 目前校园百晓生APP与CSDN软件的对比

    不忘初心.注入灵魂 设计之初 在做校园百晓生该APP时,初心是为校园的同学提供便捷的查询校园信息的服务,确实目前的软件已经实现了该功能,但是总感觉缺少一些灵魂,感觉大部分人渴望的重点在于信息而不是自己 ...

  6. 一个小例子学习makefile

    前言 makefile推荐资料为陈皓的跟我一起写makefile,需要pdf资源的可以私我 正文 目录结构 ---include ------student.h ---src ------studen ...

  7. Docker之commit制作镜像

    一.docker是什么? Docker是一个为开发人员和系统管理员提供分布式应用程序的开放平台.它是一个开源的容器引擎,基于Go语言并遵从Apche2.0协议开源. 功能:Docker可以让开发者打包 ...

  8. jquery.autocomplete的使用-----------------------摘抄别人的

    作者:lxhwss | 2011/10/11 9:46:38 | 阅读43次 document.write(”<script language=javascript src=’/js/2.js’ ...

  9. iOS开发常用技能点(持续更新中。。。)

    1,以屏幕原点开始布局  (默认从导航栏原点布局) self.extendedLayoutIncludesOpaqueBars = YES;   2,向button发送点击事件 [self.playB ...

  10. hdu2665可持久化线段树,求区间第K大

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...