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 grade**Fgrade**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
思路
  • 跟之前的PTA(Basic Level)1028.人口普查仍旧有点像,不过这里要分男女情况来比较。不过比较的内容是分数,和之前相比算简单的了
代码
#include<bits/stdc++.h>
using namespace std;
struct student
{
char name[20];
char gender;
char id[20];
int grade;
}female_high, male_low; void Init()
{
female_high.grade = -1;
male_low.grade = 110;
} bool higher(student a, student b)
{
return a.grade > b.grade;
} int main()
{
int n;
Init();
scanf("%d", &n);
student tmp;
while(n--)
{
scanf("%s %c %s %d", tmp.name, &tmp.gender, tmp.id, &tmp.grade);
if(tmp.gender == 'M' && higher(male_low, tmp))
male_low = tmp;
if(tmp.gender == 'F' && higher(tmp, female_high))
female_high = tmp;
} bool absent = false;
if(female_high.grade == -1)
{
printf("Absent\n");
absent = true;
}else printf("%s %s\n", female_high.name, female_high.id);
if(male_low.grade == 110)
{
printf("Absent\n");
absent = true;
}else printf("%s %s\n", male_low.name, male_low.id);
if(absent)
printf("NA");
else printf("%d", female_high.grade - male_low.grade);
return 0;
}
引用

https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016

PTA(Advanced Level)1036.Boys vs Girls的更多相关文章

  1. PAT (Advanced Level) 1036. Boys vs Girls (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  2. 1036 Boys vs Girls (25 分)

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

  3. PAT 1036 Boys vs Girls[简单]

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

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

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

  5. PAT 1036 Boys vs Girls (25 分)

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

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

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

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

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

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

  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 toggle()方法 语法

    jquery toggle()方法 语法 作用:toggle() 方法用于绑定两个或多个事件处理器函数,以响应被选元素的轮流的 click 事件.该方法也可用于切换被选元素的 hide() 与 sho ...

  2. Ubuntu:查询计算机软硬件信息

     造冰箱的大熊猫,本文适用于Ubuntu 16.04@cnblogs 2019/1/1 1.查询Linux内核版本 在命令行中通过命令“uname -rv”获取内核版本信息,执行实例如下所示.其中,标 ...

  3. luoguP2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...

  4. 灰度图像--图像分割 阈值处理之P-Tile阈值

    学习DIP第53天 转载请标明本文出处:***http://blog.csdn.net/tonyshengtan ***,出于尊重文章作者的劳动,转载请标明出处!文章代码已托管,欢迎共同开发:http ...

  5. Java线程之FutureTask

    简述 FutureTask是Future接口的实现类,并提供了可取消的异步处理的功能,它包含了启动和取消(start and cancel)任务的方法,同时也包含了可以返回FutureTask状态(c ...

  6. Eureka 服务注册列表显示IP问题研究

    在研究Spring Cloud的过程中,本地搭建好Eureka注册中心之后,发现Eureka服务页面显示的服务是机器名:端口的格式,并不是IP+端口的形式. 如下图: 具体搭建过程我就不再贴代码了,参 ...

  7. (转载)Zookeeper的功能以及工作原理

    本文转载自:https://www.cnblogs.com/felixzh/p/5869212.html 1.ZooKeeper是什么?       ZooKeeper是一个分布式的,开放源码的分布式 ...

  8. springboot 项目部署后 404的问题

    是因为打包的时候,没有把webapp打包进去 pom.xml 在build 里加入下面的依赖即可 <!-- resources插件,在打jar包时可以将webapp目录下的文件进行打包 --&g ...

  9. 6 Java Shell排序

    希尔排序是先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录“基本有序”时,再对全体记录进行依次直接插入排序. 1.基本思想 将待排序数组按照步长gap进行分组,然后将 ...

  10. kentico中page alias的使用

    这里设置的path or pattern,是针对于根目录而言的