PAT 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
题目解读
给出 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分) 比大小而已的更多相关文章
- 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 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- 【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 ...
- 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)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
随机推荐
- 学习vue第六节,v-if和v-show
vue 中的v-if和v-show <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- dp cf 20190613
A. Boredom 这个题目不难,但是我做的还比较复杂,不过还是很开心,至少做出来了,开始因为爆int了还wa了一发,搞得我以为自己做错了 #include <cstdio> #incl ...
- HTML往div中赋值
HTML中往div赋值 <div id="mazey">content</div> 使用JavaScript: var mazey=document.get ...
- spring mvc从后台往前台传参数的三种方式
第一种:使用Model对象(常用) 第一步:使用model对象往前台传递数据 第二步:在jsp中接收从后台传递过来的参数 第二种:使用HttpServletRequest对象 第一步:使用HttpSe ...
- spring学习笔记(一)@ConfigurationProperties注解
结论: 这个注解主要是为了将配置文件中的属性映射到实体类上,并且支持嵌套映射. 代码说明: @ConfigurationProperties(prefix = "person") ...
- apache反向代理和负载均衡
正向代理:正如我们用的游戏加速代理,大多的个人PC把请求发给正向代理服务器,代理服务器通常配置高端的带宽,替我们请求相应的服务 负载均衡中的反向代理:通常意义上,是一个请求转发的代理.类似一个收发室的 ...
- 一文教你快速修改ubuntu终端显示的主机名和用户名
为了让终端的显示更加简洁,清爽,改掉显示的用户名和主机名,改成你喜欢的名字. 创作不易,如果本文帮到了您: 如果本文帮到了您,请帮忙点个赞
- Viterbi-Algorithm(维特比)算法
CSDN博客:皮乾东 知乎:Htrying 微博:Htring的微博 微信公众号:自然语言处理爱好者(ID:NLP_lover) 文章来自:<数学之美> Viterbi-Algor ...
- 生产者消费者问题中的同步机制JAVA设计和实现
目录 问题描述 问题分析 利用记录型信号量解决 运行环境 实现思路 代码实现 运行截图 过程中出现的问题和注意点 利用AND信号集解决 运行环境 实现思路 代码实现 运行截图 问题描述 若干进程通过有 ...
- 应用视觉设计——CSS实现线性渐变效果
在freeCodeCamp中应用视觉设计的课程中,介绍了一种通过使用CSS属性实现线性渐变效果. 1.线性渐变: background:linear-gredient(gradient-directi ...