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 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>
using namespace std;
struct stu{
string name;
char gender;
string id;
int grade;
};
int main()
{
int N;cin>>N;
bool male=false,female=false;
stu tmp,maleLowest,femaleHighest;
while(N--){
cin>>tmp.name>>tmp.gender>>tmp.id>>tmp.grade;
if(tmp.gender=='M'){
/**性别为M*/
if(male==false){
male=!male;
maleLowest=tmp;
}else{
if(maleLowest.grade>tmp.grade){
maleLowest=tmp;
}
}
}else{
/**性别为F*/
if(female==false){
female=!female;
femaleHighest=tmp;
}else{
if(femaleHighest.grade<tmp.grade){
femaleHighest=tmp;
}
}
}
}
/**output*/
if(female==false) cout<<"Absent"<<endl;
else cout<<femaleHighest.name<<" "<<femaleHighest.id<<endl;
if(male==false) cout<<"Absent"<<endl;
else cout<<maleLowest.name<<" "<<maleLowest.id<<endl;
if(male==false||female==false) cout<<"NA"<<endl;
else cout<<(femaleHighest.grade-maleLowest.grade)<<endl;
system("pause");
return ;
}
PAT Advanced 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分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- 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 (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- 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 (Advanced Level) 1036. Boys vs Girls (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- Singleton(Java)
1.定义私有静态易变的类变量2.定义getInstance静态方法 2.1.若静态变量为null,则在同步类类型的同时判断静态实例是否为null, 是null则创建新实例赋给静态变量 2.2.不为nu ...
- phpstudy composer 安装
今天突然发现phpstudy 可以安装 composer 一打开php中openssl拓展 坑一 我的phpstudy 是2018最新版本,但是你下载laravel什么之类库会报错,是由于compo ...
- python正则表达式 分割字符串
使用或 标准的正则表达式有小括号,但是python的没有 # -*- coding: utf-8 -*- import sys import re import sys reload(sys) sys ...
- python读取文件乱码
方法一:使用codecs import codecs f = codecs.open('nlpir/Readme.txt','r','GBK') line = f.readline() while l ...
- python - 标准库:subprocess模块
subprocess的目的就是启动一个新的进程并且与之通信. subprocess模块中只定义了一个类: Popen. subprocess.Popen(args, bufsize=0, execut ...
- ES6中let和var的区别
通过var定义的变量,作用域是整个封闭函数,是全域的 .通过let定义的变量,作用域是在块级或是子块中. 变量提升现象:浏览器在运行代码之前会进行预解析 -不论var声明的变量处于当前作用域的第几行, ...
- Python Module_Socket_网络编程
目录 目录 Socket 套接字 套接字的原理 套接字的数据处理方式 套接字类型 Socket 标准函数 ServerSocket 标准函数 ClientSocket 标准函数 公有标准函数 Sock ...
- 阶段3 1.Mybatis_07.Mybatis的连接池及事务_3 mybatis连接池的分类
2.mybatis中的连接池 mybatis连接池提供了3种方式的配置: 配置的位置: 主配置文件SqlMapConfig.xml中的dataSourc ...
- psp周总结02
周日 周一 周二 周三 周四 周五 周六 所花时间 180 60 240 180 340 180 培训 代码量 186 65 157 86 200 200 博客量 1 1 了解的知识点 jsp页面 ...
- 虚拟机三种网络模式及Xshell与Centos7虚拟机连接
一.虚拟机的三种网络模式 1.桥接模式 a.该模式下的虚拟机可以上外网 b. 局域网之内的主机可以访问该虚拟机(做共享服务器使用) c. 该虚拟机可以和宿主机进行通信 d. 同一台主机相同模式下的虚拟 ...