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**Fgrade**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的更多相关文章

  1. PAT (Advanced Level) 1036. Boys vs Girls (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  2. 1036 Boys vs Girls (25 分)

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

  3. PAT 1036 Boys vs Girls[简单]

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

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

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

  5. PAT 1036 Boys vs Girls (25 分)

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

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

  7. 1036 Boys vs Girls (25分)(水)

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

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

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

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

随机推荐

  1. 通过JS完成电梯动画效果

    实习单位要求做一个在Vue项目中比较能适配的来反映货梯当前状况的页面效果 用JS写了一个 <!DOCTYPE html> <html> <head> <met ...

  2. php+上传视频大文件

    理清思路: 引入了两个概念:块(block)和片(chunk).每个块由一到多个片组成,而一个资源则由一到多个块组成 块是服务端的永久数据存储单位,片则只在分片上传过程中作为临时存储的单位.服务端会以 ...

  3. 修改 Idea 终端 Terminal 为 GitBash

    Terminal "C:\Program Files\Git\bin\sh.exe" -login -i

  4. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  5. finally的一个妙用

    ●传统用法try-catch-finally大家都会用:try包裹可能抛出异常的代码:catch捕获异常并对其处理:finally做一些资源关闭等回收工作.简单明了一句话就能说清. 稍微进阶一些的,大 ...

  6. R语言:时间的转化

    一般使用R从数据库导出来的时间数据一般都不是我们能看的懂的(具体是什么格式的我也忘记了),需要做如下转化 as.Date(time,origin = '1970-01-01') 最近从网上爬下来的时间 ...

  7. Walkthrough: My first WPF desktop application

    Walkthrough: My first WPF desktop application This article shows you how to develop a Windows Presen ...

  8. [Java]算术表达式求值之三(中序表达式转二叉树方案 支持小数)

    Entry类 这个类对表达式的合法性进行了粗筛: package com.hy; import java.io.BufferedReader; import java.io.IOException; ...

  9. SpringBoot解决ajax跨域问题(转载)

    一.第一种方式: 1.编写一个支持跨域请求的 Configuration import org.springframework.context.annotation.Configuration; im ...

  10. Monkeyrunner 使用说明

    monkeyrunner为android系统新公开的一个测试工具.有助于开发人员通过脚本部署较大规模的自动化测试. Monkeyrunner       本文档中包含 一个简单的monkeyrunne ...