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 ...
随机推荐
- mysql优化(下)
优化SQL语句:(1)不要使用 select *(2)尽量在where字段上添加索引:(3)模糊查询中%前置不能使用索引,比如 like ‘%a’;(4)使用or语句时,两侧语句都有索引时才使 ...
- golang配置oci8所遇到问题解决
新建文件夹 mingw 将 MinGW.zip 解压到mingw目录下,进入mingw\lib目录下 新建文件夹pkg-config 执行命令 go get github.com/wendal/go- ...
- SDOI2019R2游记
Day 0 上午到了济南,住在了山下.下午颓颓颓,zhy在玩炉石,我在...打元气!我的机器人终于不掉HP通关了呢,送的皮肤好好看啊. Day 1 到考场后,打开题面,一看第一题似乎很可做啊,好像可以 ...
- C库函数-fgets()
函数声明:char *fgets(char *str,int n,FILE *stream) 函数介绍:从指定的stream流中读取一行,并把它存储在str所指向的字符串中.当读取到(n-1)个字符时 ...
- 数据分析师面经一(bk)
2019年第一个数据分析面试: 先说一下心理感受,在BOSS多次看到这个岗位了,但是 呢一直没勇气去投这个岗位.首先毕竟是一个知名企业一万+人的公司,心里多少底气不足(小公司待习惯了吧),而且看岗位要 ...
- 一个服务器的Apache2.4.6配置多个域名
进入到Apache的配置文件:cd /etc/httpd/conf/http.conf 在后面添加: <VirtualHost *:80> # This first-listed virt ...
- ARTS打卡计划第六周
Algorithms: https://leetcode-cn.com/problems/longest-palindromic-substring/ 中心扩展法首先考虑,当然看到有个动态规划,一直很 ...
- JavaScript 高级系列之节流 [throttle] 与防抖 [debounce]
一.概念 这两个东西都是为了项目优化而出现的,官方是没有具体定义的,他们的出现主要是为了解决一些短时间内连续执行的事件带来性能上的不佳和内存的消耗巨大等问题:像这类事件一般像 scroll keyup ...
- LeetCode 36. 有效的数独(Valid Sudoku)
题目描述 判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗 ...
- SpringBoot Thymeleaf 配置多个Template Locations
@Configuration public class ThymeleafConfigration { @Bean public SpringResourceTemplateResolver firs ...