PAT甲级——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 gradeF−gradeM. 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
#include<cstdio>
#include<iostream>
using namespace std;
struct pNode{
char name[11];
char gender;
char ID[11];
int grade;
}temp,ans1,ans2;
int main()
{
ans1.grade=100;
ans2.grade=0;
bool malet=0,femalet=0,na=0;
int N;
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%s %s %s %d",temp.name,&temp.gender,temp.ID,&temp.grade);
if(temp.gender=='M')
{
if(temp.grade<ans1.grade)
{
ans1 = temp;
}
malet=true;
}
else if(temp.gender=='F')
{
if(temp.grade>ans2.grade)
{
ans2 = temp;
}
femalet=true;
}
}
if(femalet==true)
{
printf("%s %s\n",ans2.name,ans2.ID);
}
else
{
printf("Absent\n");
na=true;
}
if(malet==true)
{
printf("%s %s\n",ans1.name,ans1.ID);
}
else
{
printf("Absent\n");
na=true;
}
if(malet==true&&femalet==true)
{
printf("%d",ans2.grade-ans1.grade);
}
if(na==true)
{
printf("NA");
}
return 0;
}
PAT甲级——1036 Boys vs Girls的更多相关文章
- 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(20)
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...
- 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 ...
- PAT甲级——A1036 Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- 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 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 ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
随机推荐
- 基于百度语音识别API的Python语音识别小程序
一.功能概述 实现语音为文字,可以扩展到多种场景进行工作,这里只实现其基本的语言接收及转换功能. 在语言录入时,根据语言内容的多少与停顿时间,自动截取音频进行转换. 工作示例: 二.软件环境 操作系统 ...
- 工程日记之ChildLost(1):URLSession
URLSession 是什么 URL Loading System提供了访问URL资源的系统,提供了访问http/https/自定义URL访问的接口.其中,URLSession实例可以创建多个URLS ...
- Java语言概述-JavaSE
代码虐我千百遍,我视代码如初恋 初级学习思想: 先了解Java 下载中英文文档对照学习 多看,多学 多敲,狂练 多标注注释 总结—创造 https://baike.baidu.com/(Java百度百 ...
- (day 1)创建项目--3【创建应用】
创建步骤 1.打开命令行,进入项目中manage.py的同级目录 2.在命令行输入 python manage.py startapp blog 3.添加应用名到settings.py的INSTALL ...
- Springboot 2.x 如何解决重复提交 (本地锁的实践)
有没有遇到过这种情况:网页响应很慢,提交一次表单后发现没反应,然后你就疯狂点击提交按钮(12306就经常被这样怒怼),如果做过防重复提交还好,否则那是什么级别的灾难就不好说了... 本文主要是应用 自 ...
- UML-架构分析-架构原则
1.高内聚 2.低耦合 3.防止变异(间接性等) 4.关注点分离 方法1: 事物模块化,封装到单独的子系统中 方法2: 装饰者模式 方法3: 面向方面(AOP)
- tensorflow常用函数库
归一化函数: def norm_boxes(boxes, shape): """Converts boxes from pixel coordinates to norm ...
- Qt在vs2010下的配置
https://blog.csdn.net/chenbang110/article/details/7607250 首先不要使用中文目录, 1 下载Qt的安装包和VS2010的Qt插件 2. 安装Qt ...
- 【Gson】网页上String获取的Json数据转化为对象
1.网络上获取的String Json格式转化为对象获取数据: 需要的包:Gson Maven依赖: <!-- https://mvnrepository.com/artifact/com.go ...
- os简介
1. 操作系统(Operation System,OS) 操作系统作为接口的示意图  没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如 ...