A1036. 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>
#include<string.h>
using namespace std;
typedef struct{
char name[];
char id[];
char gender;
int grade;
}info;
int main(){
int N, absent = ;
info boy, girl, temp;
boy.grade = ;
girl.grade = -;
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%s %c %s %d", temp.name, &(temp.gender), temp.id, &(temp.grade));
if(temp.gender == 'F'){
if(temp.grade > girl.grade){
girl = temp;
strcpy(girl.name, temp.name);
strcpy(girl.id, temp.id);
}
}else if(temp.gender == 'M'){
if(temp.grade < boy.grade){
boy = temp;
strcpy(boy.name, temp.name);
strcpy(boy.id, temp.id);
}
}
}
if(girl.grade == - || boy.grade == )
absent = ;
if(girl.grade == -)
printf("Absent\n");
else
printf("%s %s\n", girl.name, girl.id);
if(boy.grade == )
printf("Absent\n");
else
printf("%s %s\n", boy.name, boy.id);
if(absent == )
printf("NA\n");
else
printf("%d", girl.grade - boy.grade);
cin >> N;
return ;
}
总结:
1、与1006一样,信息排序模拟,使用struct 结构体记录信息项。尽量边读入边处理,不需要全部存储后再排序。
A1036. Boys vs Girls的更多相关文章
- PAT A1036 Boys vs Girls(25)
AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...
- PAT甲级——A1036 Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT1036:Boys vs Girls
1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- 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 ...
随机推荐
- (4)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- Consul服务发现和消费
上一章说了 Consul服务注册 现在我要连接上Consul里面的服务 请求它们的API接口 应该怎么做呢? 1.找Consul要一台你需要的服务器 1.1 获取Consul下的所有注册的服务 u ...
- ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十四节--后台工作者HangFire与ABP框架Abp.Hangfire及扩展
返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 HangFire与Quartz.NET相比主要是HangFire的内置提供集成化的控制台,方便后台查看及监控,对于 ...
- Mysql8.0的登录大坑……(忘记登录密码也可以这么搞)
关于安装和使用就不说了,属于基本操作了: 我来重点记录一下关于使用前,使用navicat登录的时候报错,1130和2059 查看安装后随机生成的密码: grep 'temporary password ...
- 画了一张基于Spring Cloud的微服务系统架构图
- Oracle数据库冷备份与热备份操作梳理
Oracle数据库的备份方式有冷备份和热备份两种,针对这两种备份的实施过程记录如下: 一.Oracle冷备份 概念数据库在关闭状态下完成所有物理系统文件拷贝的过程,也称脱机备份.适合于非归档模式(即n ...
- mysql 多列索引的生效规则,生成1000w数据的存储过程
https://www.cnblogs.com/codeAB/p/6387148.html
- ajax多级菜单栏
1.jsp 首先ajax查询数据 <script type="text/javascript"> function targetlist() { $.ajax({ ur ...
- .NET组件介绍系列
一款开源免费的.NET文档操作组件DocX(.NET组件介绍之一)http://www.cnblogs.com/pengze0902/p/6122311.html 高效而稳定的企业级.NET Offi ...
- h5定位geolaction无法调试解决方法
昨天接到一个在h5获取经纬度的需求,看了文档后,代码其实很简单,但在浏览器上调试就比较蛋疼了... 代码: function successfulCallback(position) { consol ...
- Installing and removing VNC Connect | Red Hat | VNC Connect
https://www.realvnc.com/en/connect/docs/redhat-install-remove.html 此软件会和TigerVNC(Server)或者X11VNC Ser ...