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. 请对比 Exception 和 Error,另外,运行时异常与一般异常有什么区别?

    error指的是不可预料的错误,可能会导致程序宕机:而exception指的是在程序运行中可以预见的异常,而异常分为检查异常与一般异常,检查异常需要在程序中显示捕获并处理,一般异常可以通过程序编码来进 ...

  2. Java秒杀系统方案优化 高性能高并发实战(已完成)

    1:商品列表 2:商品详情判断是否可以开始秒杀,未开始不显示秒杀按钮显示倒计时,开始显示秒杀按钮,同时会显示验证码输入框以及验证码图片,当点击秒杀按钮的时候会首先判断验证码是否正确,如果正确会返回一个 ...

  3. hdu_2588_GCD

    The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...

  4. 如何在linux中创建虚拟环境

    安装虚拟环境的命令 : sudo pip install virtualenv sudo pip install virtualenvwrapper 安装完虚拟环境后,如果提示找不到mkvirtual ...

  5. JavaScript--动态添加元素

    在网页中,使用JavaScript动态创建元素的方式有三种: 1.document.write() 2.Element.innerHTML 3.document.createElement() 在上述 ...

  6. mysql创建表时反引号的作用

    试用navicat工具查看现网mysql建表语句时,发现表名和字段名都是反引号引起来的 CREATE TABLE `tab_notice_title_tv` ( `i_id` ) NOT NULL A ...

  7. video.js使用技巧

    https://www.awaimai.com/2053.html https://www.jianshu.com/p/16fa00a1ca8e

  8. 图的遍历(Python实现)

    图的遍历(Python实现) 记录两种图的遍历算法——广度优先(BFS)与深度优先(DFS). 图(graph)在物理存储上采用邻接表,而邻接表是用python中的字典来实现的. 两种遍历方式的代码如 ...

  9. 图片验证码给AI使用

    为了破解图形验证码,AI需要大量的图片数据.为了简单获取大量的图形来喂给Ai模型训练,索性自己写一把.代码来一发..   import java.awt.Color; import java.awt. ...

  10. windows 系统禁止使用 U 盘的方法

    windows 系统禁止使用 U 盘的方法 最简单的办法: 注册表 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentCntrolSet\Services\USBSTOR] 将名为 ...