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. jQuery基础知识1

    jquery的概念 js query jquery库 封装了大量js,封装js的入口函数.兼容性问题.DOM操作.事件.ajax 使用jquery 下载包 引用 <script src=&quo ...

  2. python中IO多路复用、协程

    一.IO多路复用 IO多路复用:检测多个socket是否已经发生变化(是否已经连接成功/是否已经获取数据)(可读/可写) import socket def get_data(key): client ...

  3. centos6.5上安装git

    亲测有效 https://blog.csdn.net/wxy540843763/article/details/80197301

  4. NodeJS 开发博客(四) 日志及安全攻击

    node 操作文件: const fs = require('fs'); const path = require('path'); const filename = path.resolve(__d ...

  5. 17 webpack中babel的配置

    在webpack中,默认只能处理一部分ES6的新语法,一些更高级的ES6语法或者ES7语法, webpack是处理不了的:这时候,就需要借助于第三方的loader,来帮助webpack处理这些高级的语 ...

  6. 2.3 vue配置(上)

    rm,在打包之前把上一次打包之后的东西删掉,然后webpack重新打包 通过DefinePlugin形成一个环境变量 HTML打包插件

  7. 01_Request和Response

    参考文档 http://www.iamnancy.top/djangorestframework/Responses/ https://q1mi.github.io/Django-REST-frame ...

  8. springboot启动时执行任务CommandLineRunner

    # SpringBoot中CommandLineRunner的作用> 平常开发中有可能需要实现在项目启动后执行的功能,SpringBoot提供的一种简单的实现方案就是添加一个model并实现Co ...

  9. [Luogu] 选学霸

    https://www.luogu.org/problemnew/show/P2170 并查集+DP #include <iostream> #include <cstring> ...

  10. surprise库官方文档分析(一)

    一:入门 1.基本用法 (1).自动交叉验证 Surprise有一套内置的 算法和数据集供您使用.在最简单的形式中,只需几行代码即可运行交叉验证程序: from surprise import SVD ...