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一遍找最大最小值,水题 # ...
随机推荐
- Spring Boot 整合Web 层技术(整合Servlet)
1 整合Servlet 方式一1.1通过注解扫描完成Servlet 组件的注册 1.1.1创建Servlet /*** 整合Servlet 方式一*/@WebServlet(name = & ...
- 微信小程序下拉刷新时有部分区域不随着下拉移动
问题 区域元素使用(position: fixed),小程序页面下拉刷新时,这部分区域不会随页面下拉移动. 如何解决 删除设置的top属性
- Linux Kernel Makefiles Kbuild en
来自Linux kernel docs,顺便整理了一下排版 Linux Kernel Makefiles This document describes the Linux kernel Makefi ...
- Java Stream 流如何进行合并操作
1. 前言 Java Stream Api 提供了很多有用的 Api 让我们很方便将集合或者多个同类型的元素转换为流进行操作.今天我们来看看如何合并 Stream 流. 2. Stream 流的合并 ...
- 3D三栅极晶体管(摘抄)
英特尔的科学家们在2002年发明了三栅极晶体管——这是根据栅极有三面而取名的. 传统“扁平的”2D平面栅极被超级纤薄的.从硅基体垂直竖起的3D硅鳍状物所代替.电流控制是通过在鳍状物三面的每一面安装一个 ...
- [hdu4609]计数方法,FFT
题目:给一个数组a,从里面任选三个数,求以这三个数为三条边能构成三角形的概率. 思路:由于每个数只能用一次,所以考虑枚举三边中的最大边.先将a数组排序,然后枚举它的每个数x作为最大边,那么问题就是要求 ...
- 简述SpringCloud底层原理
目录 一.业务场景介绍 二.Spring Cloud核心组件:Eureka 三.Spring Cloud核心组件:Feign 四.Spring Cloud核心组件:Ribbon 五.Spring Cl ...
- 系列13 docker asp.net core部署
一.介绍 本篇完整介绍asp.net core web api如何部署到docker容器中,并通过外部访问web api服务.在编写完成dockerfile之后,可以通过docker [image ...
- flask之request
from flask import Flask, render_template, redirect, jsonify, send_file, request, session app = Flask ...
- MYSQL的DOUBLE WRITE双写
期待未来超高速大容量的固态硬盘普及时,只需要CHECKPOINT,而不再需要各种各样的BUFFER,CACHE了 DOUBLE WRITE 在InnoDB将BP中的Dirty Page刷(flush) ...