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 namegenderID 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 grade​F​​−grade​M​​. 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 分)(简单题)的更多相关文章

  1. 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 ...

  2. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  3. PAT 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  4. 1036 Boys vs Girls (25分)(水)

    1036 Boys vs Girls (25分)   This time you are asked to tell the difference between the lowest grade o ...

  5. 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 ...

  6. PAT 1036 Boys vs Girls (25分) 比大小而已

    题目 This time you are asked to tell the difference between the lowest grade of all the male students ...

  7. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  8. 【PAT甲级】1036 Boys vs Girls (25 分)

    题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...

  9. 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 ...

随机推荐

  1. Class文件中的常量

    常量池计数器 常量池是class文件中非常重要的结构,它描述着整个class文件的字面量信息. 常量池是由一组constant_pool结构体数组组成的,而数组的大小则由常量池计数器指定. 常量池计数 ...

  2. P2002 消息扩散[SCC缩点]

    题目描述 有n个城市,中间有单向道路连接,消息会沿着道路扩散,现在给出n个城市及其之间的道路,问至少需要在几个城市发布消息才能让这所有n个城市都得到消息. 输入格式 第一行两个整数n,m表示n个城市, ...

  3. P1351 联合权值[鬼畜解法]

    题目描述 无向连通图 G 有 n 个点,n−1 条边.点从 1 到 n 依次编号,编号为 i 的点的权值为 Wi​,每条边的长度均为 1.图上两点 (u,v) 的距离定义为 u 点到 v 点的最短距离 ...

  4. 1260:【例9.4】拦截导弹(Noip1999)

    题目来源:http://ybt.ssoier.cn:8088/problem_show.php?pid=1260 1260:[例9.4]拦截导弹(Noip1999) 时间限制: 1000 ms     ...

  5. go mod使用

    GO111MODULE 有三个值:off, on和auto(默认值) GO111MODULE=off,go命令行将不会支持module功能,寻找依赖包的方式将会沿用旧版本那种通过vendor目录或者G ...

  6. python实现字符串中如果遇到连续重复的字符只出现一次非去重

    需求:在一个字符串中, 如果遇到连续重复的字符只出现一个,(不是去重) 例:str1 = 'aabbccddaabbccdd' 输出结果为:‘abcdabcd’ 具体实现代码如下: def func( ...

  7. div 水平垂直居中

    css <style> .main{ background: #999999; width: 600px; height: 400px; position: absolute; top: ...

  8. Poj 2599 Godfather(树的重心)

    Godfather Time Limit: 2000MS Memory Limit: 65536K Description Last years Chicago was full of gangste ...

  9. yii2.0 模块的使用

    以高级模板为例 1.复制目录 frontend或backend 为一个新目录pro修改advanced\common\config\bootstrap.php 添加一行,加载刚才的路劲Yii::set ...

  10. label设置渐变时不显示纯英文纯数字字符串

    提出问题: 当对UILabel设置渐变color时,有点小问题.即:text为中文或中英混合字符串时显示正常,纯英文字符串不显示!!!   剖析问题: 经搜索了解到:在显示中文时,绘制渐变color的 ...