PTA(Advanced Level)1036.Boys vs Girls
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**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
思路
- 跟之前的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的更多相关文章
- PAT (Advanced Level) 1036. Boys vs Girls (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- 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 ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- 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 ...
随机推荐
- AJAX 请求完成时执行函数。Ajax 事件。
ajaxComplete(callback) 概述 AJAX 请求完成时执行函数.Ajax 事件. XMLHttpRequest 对象和设置作为参数传递给回调函数.大理石直角尺 参数 callback ...
- 使用kombu的producer pool 向rabbitmq瞬间发送大量消息
kombu比pika感觉考虑得全面多了,不知道为什么用的人好像少? 生产端是 python-socket.io 的client 接受socketio 消息后, 发到rabbitmq 按时序进行处理 ...
- 在Latex中,拉普拉斯算子的小写符号l怎么表示
如下图所示的小写字母l,在Latex中不知道该如何表示,试过用\mathcal但是发现不行,因为\mathcal只支持大写字母. 正确方法: \ell
- LVS集群之NAT模式
集群的分类: (1)HA:高可用集群,有叫双机热备 原理:两台机器A.B,正常是A提供服务,当A机宕机或者服务有问题时,会切换到B机继续提供服务常用的高了永软件:heartbeat和keepalive ...
- (转载)深入理解Java:内省(Introspector)
本文转载自:https://www.cnblogs.com/peida/archive/2013/06/03/3090842.html 一些概念: 内省(Introspector) 是Java 语言对 ...
- Mac 10.15 关闭SIP
升级Mac后SIP开启了,根目录不能创建文件了 关闭 sip,终端输入 sudo mount -uw / 在我们开发过程中,有时候我们安装一些工具软件需要将文件拷贝到系统限制更改的文件夹中,甚至有时需 ...
- Liunx 命令之链接操作
Linux 系统中有软链接和硬链接两种特殊的"文件". 软链接可以看作是Windows中的快捷方式,可以让你快速链接到目标档案或目录. 硬链接则透过文件系统的inode来产生新档名 ...
- JS遍历OCX方法
/----查看OCX组件的属性 <html> <head> <title>OCX</title> <meta http-equiv="C ...
- 使用微软易升安装纯净版win10
1.打开官方网址 https://www.microsoft.com/zh-cn/software-download/windows10 2.下载工具 3.根据你的需求,我这里是给另外以外机器安装,一 ...
- 在oracle中使用基表建立月表的存储过程
某些系统需要按月分表来保存数据.下面的存储过程演示了如何使用基表来建立每个月的月表. 处理思路是: 1:首先,为基表建立好表和对应的索引. 2:将基表保存到一个存储过程需要的表中. ...