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. 使用Topshelf创建Windows服务[转载]

    概述 Topshelf是创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with Topshelf通过5个步骤详细的 ...

  2. TOMCAT与http

    一.Tomcat是什么?Tomcat是一个Web应用服务器,同时也是一个Servlet/JSP容器.Tomcat作为Servlet容器,负责处理客户端请求,把请求传送给Servlet,并将Servle ...

  3. 服务如何配置JVM

    为了使JVM的资源利用更合理,往往需要手动设置JVM的初始值.下面将详细介绍不同环境下的JVM配置. 1.如果是应用程序,则:java -Xms800m -Xmx800m 你的类名 java -Xms ...

  4. node 异步回调 —迭代记录

    1.0  开始时node采用了基础的js回调形势 const fs = require('fs'); fs.readFile('./package.json',(err,data) => { i ...

  5. 树莓派远程桌面--使用windows自带的远程桌面软件mstsc.exe

    步骤: 1.使用SSH登录树莓派 2.安装xrdp服务: sudo apt-get install xrdp 3.在Windows下打开命令框运行:mstsc 4.登录树莓派桌面 5.登录成功

  6. 056_统计/etc/passwd 中 root 出现的次数

    #!/bin/bash#每读取一行文件内容,即从第 1 列循环到最后 1 列,依次判断是否包含 root 关键词,如果包含则 x++awk -F: '{i=1;while(i<=NF){if($ ...

  7. Windows下有用的工具推荐

    1.ConEmu多标签命令行工具https://download.fosshub.com/Protected/expiretime=1495446879;badurl=aHR0cDovL3d3dy5m ...

  8. 使用 Java 创建聊天客户端-1

    1.聊天客户端文本框的搭建. 项目截图:java project 代码: (1).ChatManager.java package com.nantian.javachatclient.main; i ...

  9. jQuery相关方法9----事件相关

    一.事件冒泡和阻止事件冒泡 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></s ...

  10. PHP sha1()函数

    <!DOCTYPE html> <html> <body> <?php $str = "dashu"; echo sha1($str); ...