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 ...
随机推荐
- dataGridView添加ComboBox 每行绑定不同的集合,显示默认值
好了 多说无意,直接上代码,看不看的懂,就看大家的了,解决问题后,可以评论回复,可以一起商讨一些疑难杂症 List<ProtocolInfo> list = piDB.FindAll(). ...
- luoguP2863 [USACO06JAN]牛的舞会The Cow Prom
P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...
- flask 第八篇 实例化flask时的参数配置
Flask 是一个非常灵活且短小精干的web框架 , 那么灵活性从什么地方体现呢? 有一个神奇的东西叫 Flask配置 , 这个东西怎么用呢? 它能给我们带来怎么样的方便呢? 首先展示一下: from ...
- C++入门经典-例6.22-字符串与数组,string类型的数组
1:数组中存储的数据也可以是string类型的.代码如下: // 6.22.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include ...
- dubbo的实现原理
dubbo的介绍 dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的RPC实现服务的输出和输入功能,可以和Spring框架无缝集成. dubbo框架是基于Spring容器运 ...
- ubuntu安装mysql 5.7
1.安装mysql sudo apt-get install mysql-client mysql-server 2.启动 service mysqld start 3.登陆 mysql -uroot ...
- 如何查看 SELinux状态及关闭SELinux
查看SELinux状态: 1./usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: ...
- [Java]算术表达式组建二叉树,再由二叉树得到算式的后序和中序表达式
Entry类: package com.hy; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...
- js 中文字符串转base64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- RGB颜色透明度转换
100% — FF95% — F290% — E685% — D980% — CC75% — BF70% — B365% — A660% — 9955% — 8C50% — 8045% — 7340% ...