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

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

时间复杂度:$O(N)$

代码:

#include <bits/stdc++.h>
using namespace std; int N; struct Students {
char name[20];
char sex[5];
char num[20];
int Grade;
}students[100100]; /*bool cmp(const Students& a, const Students& b) {
if(a.sex != b.sex)
return a.sex > b.sex;
else
return a.Grade > b.Grade;
}*/ int main() {
scanf("%d", &N);
for(int i = 1; i <= N; i ++)
scanf("%s%s%s%d", students[i].name, students[i].sex, students[i].num, &students[i].Grade); int m = 0, f = 0;
//sort(students + 1, students + 1 + N, cmp); int s1 = 999, s2 = -999;
int temp1 = 0, temp2 = 0;
for(int i = 1; i <= N; i ++) {
if(strcmp(students[i].sex, "M") == 0) {
if(students[i].Grade < s1) {
s1 = students[i].Grade;
temp1 = i;
}
} else {
if(students[i].Grade > s2) {
s2 = students[i].Grade;
temp2 = i;
}
}
} for(int i = 1; i <= N; i ++) {
if(strcmp(students[i].sex, "M") == 0)
m ++;
else
f ++;
} if(f == 0)
printf("Absent\n%s %s\nNA\n", students[temp1].name, students[temp1].num);
else if(m == 0)
printf("%s %s\nAbsent\nNA\n", students[temp2].name, students[temp2].num);
else {
printf("%s %s\n", students[temp2].name, students[temp2].num);
printf("%s %s\n", students[temp1].name, students[temp1].num);
printf("%d\n", students[temp2].Grade - students[temp1].Grade);
} return 0;
}

  

PAT 甲级 1036 Boys vs Girls(20)的更多相关文章

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

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

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

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

  4. PAT甲级——A1036 Boys vs Girls

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

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

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

  6. PAT 1036 Boys vs Girls[简单]

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

  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. 1036 Boys vs Girls (25 分)

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

  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. c/c++ 表白小程序

    1.开发工具: vs  vc(任选一个) 2.准备材料 : a.一首音乐 (注意:音乐要求重命名为  “x”  ) b.20张图片(注意: 图片要求重命名为  “1”  "2"   ...

  2. HDU1159(LCS)

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> us ...

  3. Java分享笔记:RandomAccessFile流 & 在文件指定位置插入内容

    RandomAccessFile流:随机存取文件流,该类定义了一个记录指针,通过移动指针可以访问文件的任意位置,且对文件既可以读也可以写.使用该类的write方法对文件写入时,实际上是一种覆盖效果,即 ...

  4. .net core 发布到docker

    1. 安装docker-desktop,windows环境安装包 官方网站:https://www.docker.com/ 2.注册登陆Docker账号 安装成功后,在官方网站注册一个账号,使用账号登 ...

  5. 第四课:PHP 变量

    变量指程序中使用的数值是可以变化的量,与常量(一旦被定义,就无法改变)相反. 变量是用于存储信息的"容器": 实例 <?php $x=5; $y=6; $z=$x+$y; e ...

  6. CentOS下禁止防火墙

    CentOS下禁止防火墙 1.使用如下命令安装iptables-services. yum install -y iptables-services 2.关闭防火墙. service iptables ...

  7. eclipse全选包

    按住shift键,点击第一个jar包,然后点击最后一个jar包,就全选了所有jar包,然后添加build path 添加到类路径

  8. ecshop 全系列版本网站漏洞 远程代码执行sql注入漏洞

    ecshop漏洞于2018年9月12日被某安全组织披露爆出,该漏洞受影响范围较广,ecshop2.73版本以及目前最新的3.0.3.6.4.0版本都受此次ecshop漏洞的影响,主要漏洞是利用远程代码 ...

  9. Python自动化运维——文件内容差异对比

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:difflib 安装:Python版本大于等于2.3系统自带 功能:对比文本之间的差异,而且支持输出可读性比 ...

  10. (数据科学学习手札05)Python与R数据读入存出方式的总结与比较

    在数据分析的过程中,外部数据的导入和数据的导出是非常关键的部分,而Python和R在这方面大同小异,且针对不同的包或模块,对应着不同的函数来完成这部分功能: Python 1.TXT文件 导入: 以某 ...