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 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
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
string name;
char sex;
string id;
int score;
}a[];
int main()
{
int n;
while(cin>>n){
int num_M=,num_F=;
int index_M=,index_F=;
int min_M=,max_F=;
for(int i=;i<n;i++){
cin>>a[i].name>>a[i].sex>>a[i].id>>a[i].score;
if(a[i].sex=='M'){
num_M++;
if(a[i].score<min_M){
index_M=i;
min_M=a[i].score;
}
}else if(a[i].sex=='F'){
num_F++;
if(a[i].score>max_F){
index_F=i;
max_F=a[i].score;
}
} }
if(num_F==){
cout<<"Absent"<<endl;
}else{
cout<<a[index_F].name<<" "<<a[index_F].id<<endl;
}
if(num_M==){
cout<<"Absent"<<endl;
}else{
cout<<a[index_M].name<<" "<<a[index_M].id<<endl;
}
if(num_M==||num_F==){
cout<<"NA"<<endl;
}else{
cout<<a[index_F].score-a[index_M].score<<endl;
}
}
return ;
}
PAT (Advanced Level) Practice 1036 Boys vs Girls (25 分)的更多相关文章
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- 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 ...
- 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 ...
随机推荐
- Mac安装Mysql-python遇到的坑,被这俩报错反复摩擦:'my_config.h' file not found 和 IndexError: string index out of range
最后Stackoverflow上面的大神解决了问题: Link brew install mysql brew unlink mysql brew install mysql-connector-c ...
- Python3(二) 表示‘组’的概念与定义
现实世界中总存在一组一组的事物, 一.列表的定义 type(['hello','world',1,9,True,False]) = <class 'list'> type([[1,2,3, ...
- ssh_key认证
ssh认证流程步骤: 1.主机host_key认证 2.身份验证 3.身份验证通过 原理及更多知识点,请查看好友博客 http://www.cnblogs.com/f-ck-need-u/p/7129 ...
- Apache安装使用笔记
下载 打开网页http://httpd.apache.org/,点击 在download页面点击 然后在新页面选择 在新窗口选择 选择32位或64位apache下载,此处下载64位的apache: h ...
- SharePoint 生产环境文件归档
前言 最近,用户提出数据库大小太大,所以,希望把文件归档.至于归档,该怎么做呢? 正文 我们提出的解决方案,占用数据库最主要的就是各种文档,那就按照时间为限制,超过一年的文档全部备份,由用户的IT自行 ...
- [PHP] 使用PHP在mongodb中进行count查询
在php7的mongodb扩展中,当要查询某个集合在某个条件下的数据个数时,可以使用下面的方式来获取. 比原生的命令要复杂许多 比旧版mongo扩展也复杂许多 需要使用到MongoDB\Driver\ ...
- Javascript 基础学习(七)常用内置对象
Array 定义 数组也是一个对象,是一个用来存储数据的对象.和Object类似,但是它的存储效率比普通对象要高.数组中保存的内容我们称为元素.数组使用索引(index)来操作元素.索引指由0开始的整 ...
- 软件测试常见术语(英->汉)收藏好随时备用!
Defect 缺陷Defect Rate 缺陷率Verification & Validation 验证和确认Failure 故障White-box Testing 白盒测试Black-box ...
- Kubernetes CI/CD(2)
本章节通过在Jenkins创建一个kubernetes云环境,动态的在kubernetes集群中创建pod完成pipeline的构建流程,关于直接在宿主机上搭建Jenkins集群的可参照Kuberne ...
- Python核心编程:《8个实践性建议》
前言 我们在用Python进行机器学习建模项目的时候,每个人都会有自己的一套项目文件管理的习惯,我自己也有一套方法,是自己曾经踩过的坑踩过的雷总结出来的,现在在这里分享一下给大家,因为很多伙伴是接触P ...