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. 我的第一个Python程序

    #我的第一个Python程序 def is_valid_date(strdate): #判断是否是一个有效的日期字符串 try: #判断是否是时间格式 if ":" in strd ...

  2. poj 3694 Network : o(n) tarjan + O(n) lca + O(m) 维护 总复杂度 O(m*q)

    /** problem: http://poj.org/problem?id=3694 问每加一条边后剩下多少桥 因为是无向图,所以使用tarjan缩点后会成一棵树并维护pre数组 在树上连一条边(a ...

  3. Zabbix源码安装部署

    zabbix源码部署安装 参考文档:https://www.zabbix.com/documentation/4.0/manual/installation/install ​ https://www ...

  4. vue 导出流文件excel

    第一种方法:需要设置响应类型,这里还需要安装 npm install js-file-download --save ,然后引用 var fileDownload = require('js-file ...

  5. Flask初学者:url_for

    URL反转:反转是指通过视图函数名称得到其对应的URL(有反转也就有正转,即通过URL得到视图函数返回的内容,也就是我们平时的访问网页了),需要“url_for(endpoint, **values) ...

  6. Scrapy框架的基本使用

    安装 pip install scrapy 基础使用 1. 创建一个工程:scrapy startproject 2. 在工程目录下创建一个爬虫文件 cd 工程 scrapy genspider 爬虫 ...

  7. R语言绘图:直方图

    使用ggplot2包绘制直方图 ######*****绘制直方图代码*****####### data1 <- data0[(data0[, 2] <= 500) & (data0 ...

  8. P2153 [SDOI2009]晨跑(最小费用最大流)

    题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...

  9. javascript实现浏览器管理员工具鼠标获取Html元素 并生成 xpath

    javascript实现浏览器管理员工具鼠标获取Html元素 并生成 xpath 看看标题就被吓尿了,够长吧.让我们看看到底是个什么玩意.. 直接上图: 就是这个东东了,做为一个写爬虫的,有必要了解下 ...

  10. WPF中的命令与命令绑定(二)

    原文:WPF中的命令与命令绑定(二) WPF中的命令与命令绑定(二)                                              周银辉在WPF中,命令(Commandi ...