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. J-query extend()方法

    1.如果没有冲突参数会弥在后面. 2.参数如果和前面的参数存在相同的名称,那么后面的会覆盖前面的参数值.

  2. BugkuCTF SQL注入1

    前言 写了这么久的web题,算是把它基础部分都刷完了一遍,以下的几天将持续更新BugkuCTF WEB部分的题解,为了不影响阅读,所以每道题的题解都以单独一篇文章的形式发表,感谢大家一直以来的支持和理 ...

  3. Spark Streaming简介及原理

    简介: SparkStreaming是一套框架. SparkStreaming是Spark核心API的一个扩展,可以实现高吞吐量的,具备容错机制的实时流数据处理. 支持多种数据源获取数据: Spark ...

  4. BZOJ3782 上学路线

    设障碍个数为,\(obs\)则一般的容斥复杂度为\(O(2^{obs})\).但因为这个题是网格图,我们可以用DP解.设\(f[i]\)表示不经过任何障碍到达第\(i\)个障碍的方案数,转移时枚举可以 ...

  5. this.$http.post ||this.$http.put||vue 获取url参

    getClasslist() { this.$http.get('/xxxxx/childlist', { params: { ServiceUnitId: localStorage.getItem( ...

  6. M2阶段测试报告

    一.安全漏洞测试报告: http://files.cnblogs.com/hotsbuaa/M2-安全漏洞测试.pdf 二.全面兼容测试: http://files.cnblogs.com/hotsb ...

  7. BugPhobia发布篇章:Beta版本学霸在线系统正式发布

    0x00:测试报告版本管理 版本号 具体细节 修订时间 V 1.0 整理第一轮迭代用户管理和登陆注册的功能性验证测试,预计将继续网页对浏览器版本的兼容性测试 2015/11/12 V1.0.1 整理第 ...

  8. junit4实验报告

    一:题目简介 测试一个加.减.乘.除. 二:源码的github链接 https://github.com/wangyuefang/test/blob/master/daiceshilei.md htt ...

  9. linux_软件安装

    一.在线安装(apt) APT是Advance Packaging Tool(高级包装工具)的缩写,APT可以自动下载,配置,安装二进制或者源代码格式的软件包,简化了Unix系统上管理软件的过程. 1 ...

  10. auto_increment 自增键的一些说明

    导致auto_increment变小的几种情况: 1. alter table xx auto_increment = yy; 2. truncate table 3. restart mysql 第 ...