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
题解:
要注意absent的顺序
题目大意: 给N个学生的成绩、名字、ID和分数,还有性别(gender)。分别找出男孩子分数最低和女孩子分数最高的,打印名字和ID,然后求两者的成绩差,如果某一方不存在,那么打印Absent,分数差值为NA。
AC代码:
#include<bits/stdc++.h>
using namespace std;
string nm;
char ge;
string id;
int grade;
int n;
int main(){
int n;
cin>>n;
string fn="",mn="";
string fid,mid;
int fg=-,mg=;
for(int i=;i<=n;i++)
{
cin>>nm>>ge>>id>>grade;
if(ge=='F'){
if(grade>fg){
fg=grade;
fn=nm;
fid=id;
}
}
if(ge=='M'){
if(grade<mg){
mg=grade;
mn=nm;
mid=id;
}
}
}
if(fg<){
cout<<"Absent"<<endl;//注意absent的顺序
cout<<mn<<" "<<mid<<endl;
cout<<"NA";
}
else if(mg>){
cout<<fn<<" "<<fid<<endl;
cout<<"Absent"<<endl;//注意absent的顺序
cout<<"NA"<<endl;
}else{
cout<<fn<<" "<<fid<<endl;
cout<<mn<<" "<<mid<<endl;
cout<<fg-mg<<endl;
}
return ;
}
PAT 甲级 1036 Boys vs Girls (25 分)(简单题)的更多相关文章
- 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 (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
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 (25分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 【PAT甲级】1036 Boys vs Girls (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- 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 ...
随机推荐
- 容器上使用Docker还是Rocket?为什么不一起用呢?
在2014年接近尾声时,CoreOS在Docker发布了Rocket,声称Docker的流程模型有着“根本性的缺陷”.虽然CoreOS的创始人Alex Polvi尽量缓和语气,但是他坚持自己的基本观点 ...
- MyCat(1.1)Mycat基本介绍
[1]学习目的 (1)掌握在数据库负载增大时的处理方法 (2)理解mycat的基础概念 (3)掌握mycat基础配置和监控方法 [2]Mycat的前世今生 官网:http://mycat.io/ 下载 ...
- RMQ问题【模板】
概念 RMQ 是英文 Range Maximum/Minimum Query 的缩写,表示区间最大(最小)值. 解决 RMQ 问题的主要方法有两种,分别是 ST 表和线段树.本文主要讲 ST 表. S ...
- 将 Django 应用程序部署到生产服务器
原文出自: http://www.ibm.com/developerworks/cn/opensource/os-django/ 比较有启发性质的一篇文章,会避免很多弯路 Django 是一个基于 P ...
- java线程中yield(),sleep(),wait()区别详解
1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchronized同步快,其他线程仍然不能访问共享数据.注意该方 ...
- MongoDB journal 与 oplog,究竟谁先写入?
MongoDB journal 与 oplog,谁先写入?最近经常被人问到,本文主要科普一下 MongoDB 里 oplog 以及 journal 这两个概念. journal journal 是 M ...
- CF359D Pair of Numbers gcd+暴力
利用区间 gcd 个数不超过 log 种来做就可以了~ code: #include <bits/stdc++.h> #define N 300005 #define setIO(s) f ...
- 差分约束 4416 FFF 团卧底的后宫
/* 4416 FFF 团卧底的后宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 你在某日收到了 FFF ...
- 02_Kibana的安装
Kibana部署 1. 下载Kibana $ wget https://artifacts.elastic.co/downloads/kibana/kibana-6.6.0-linux-x86_64. ...
- 特征工程学习01-sklearn单机特征工程
特征工程学习01-sklearn单机特征工程 小书匠 kindle 0.数据的导入 from sklearn.datasets import load_iris #导入IRIS数据集 iris= ...