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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
typedef struct{
char name[];
char id[];
char gender;
int grade;
}info;
int main(){
int N, absent = ;
info boy, girl, temp;
boy.grade = ;
girl.grade = -;
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%s %c %s %d", temp.name, &(temp.gender), temp.id, &(temp.grade));
if(temp.gender == 'F'){
if(temp.grade > girl.grade){
girl = temp;
strcpy(girl.name, temp.name);
strcpy(girl.id, temp.id);
}
}else if(temp.gender == 'M'){
if(temp.grade < boy.grade){
boy = temp;
strcpy(boy.name, temp.name);
strcpy(boy.id, temp.id);
}
}
}
if(girl.grade == - || boy.grade == )
absent = ;
if(girl.grade == -)
printf("Absent\n");
else
printf("%s %s\n", girl.name, girl.id);
if(boy.grade == )
printf("Absent\n");
else
printf("%s %s\n", boy.name, boy.id);
if(absent == )
printf("NA\n");
else
printf("%d", girl.grade - boy.grade);
cin >> N;
return ;
}

总结:

1、与1006一样,信息排序模拟,使用struct 结构体记录信息项。尽量边读入边处理,不需要全部存储后再排序。

A1036. Boys vs Girls的更多相关文章

  1. PAT A1036 Boys vs Girls(25)

    AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...

  2. PAT甲级——A1036 Boys vs Girls

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

  3. 1036 Boys vs Girls (25 分)

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

  4. PAT1036:Boys vs Girls

    1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...

  5. PAT 1036 Boys vs Girls[简单]

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

  6. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

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

  7. PAT 1036 Boys vs Girls (25 分)

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

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

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

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

随机推荐

  1. SpringMvc返回Json调试

    spring-web-5.0.6.RELEASE.jar!/org/springframework/web/method/support/HandlerMethodReturnValueHandler ...

  2. Mac下通过VMware Fusion安装centos虚拟机操作记录

    下面介绍下利用VMware Fusion工具在Mac上安装centos虚拟机的做法:1)下载VMware Fusion工具下载地址(包括注册码):http://www.macx.cn/thread-2 ...

  3. python基础学习笔记(三)

    序列概览 Python 包含6 种内建的序列,这里重点讨论最常用的两种类型:列表和元组. 列表与元组的主要区别在于,列表可以修改,元组则不能.也就是说如果要根据要求来添加元素,那么列表可以会更好用:而 ...

  4. sql-server安装

    ubuntu安装sql-server https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-ubuntu?view ...

  5. M1/M2 总结

    时光是一列不会回头的列车. 这一学期这么快就过去了,当时刚开始软件工程的那些日子还历历在目.不知道那些如风般过去的日子带给我了什么.然而我又清楚地认识到自己已经改变了. 刚开始软件工程的时候,我对团队 ...

  6. 现代程序设计 homework-02

    首先显示博客要求: 描述在这么多相似的需求面前, 你怎么维护你的设计 (父类/子类/基类, UML, 设计模式,  或者其它方法) 让整个程序的架构不至于崩溃的? 建议从后往前来搞,比如我通读一遍需求 ...

  7. 量产救U盘

    同事U盘不能格式化,快速格式化失败,非快速格式化也失败.就问谁有360安全软件,试试能不能格式化. 我说我有火绒,但是不知道火绒并没有格式化U盘的功能(应该没有吧,反正我找了以后没找到) 那怎么办呢? ...

  8. jeecg 主-附表生成代码例子

    jeecg 主-附表生成代码例子 - CSDN博客https://blog.csdn.net/u010411264/article/details/51243277 JEECG Online Codi ...

  9. Docker(十四)-Docker四种网络模式

    Docker 安装时会自动在 host 上创建三个网络,我们可用 docker network ls 命令查看: none模式,使用--net=none指定,该模式关闭了容器的网络功能. host模式 ...

  10. [转帖]关于网络编程中MTU、TCP、UDP优化配置的一些总结

    关于网络编程中MTU.TCP.UDP优化配置的一些总结 https://www.cnblogs.com/maowang1991/archive/2013/04/15/3022955.html 感谢原作 ...