PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
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
题解:
要注意absent的顺序
题目大意: 给N个学生的成绩、名字、ID和分数,还有性别(gender)。分别找出男孩子分数最低和女孩子分数最高的,打印名字和ID,然后求两者的成绩差,如果某一方不存在,那么打印Absent,分数差值为NA。
AC代码:
#include<bits/stdc++.h>
using namespace std;
string nm;
char ge;
string id;
int grade;
int n;
int main(){
int n;
cin>>n;
string fn="",mn="";
string fid,mid;
int fg=-,mg=;
for(int i=;i<=n;i++)
{
cin>>nm>>ge>>id>>grade;
if(ge=='F'){
if(grade>fg){
fg=grade;
fn=nm;
fid=id;
}
}
if(ge=='M'){
if(grade<mg){
mg=grade;
mn=nm;
mid=id;
}
}
}
if(fg<){
cout<<"Absent"<<endl;//注意absent的顺序
cout<<mn<<" "<<mid<<endl;
cout<<"NA";
}
else if(mg>){
cout<<fn<<" "<<fid<<endl;
cout<<"Absent"<<endl;//注意absent的顺序
cout<<"NA"<<endl;
}else{
cout<<fn<<" "<<fid<<endl;
cout<<mn<<" "<<mid<<endl;
cout<<fg-mg<<endl;
}
return ;
}
PAT 甲级 1036 Boys vs Girls (25 分)(简单题)的更多相关文章
- 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甲级: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 (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 o ...
- 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 ...
- PAT 1036 Boys vs Girls (25分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 【PAT甲级】1036 Boys vs Girls (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- 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语法
数据库概念 将保存的数据部分,存到一个公共的地方,所有的用户涉及到数据相关都必须来这个公共地方查找 MySQL 本质就是一款基于网络通信的应用软件,任何基于网络通信的软件底层都是socket 可以把M ...
- java对象转换
对象转换: 对象的分层涉及到各个层级之间的对象转换(Entity2DTO , DTO2VO, VO2DTO,DTO2Entity等),传统的采用set/get 方法硬编码实现写的代码比较多:或者采用B ...
- JQuery制作网页——表单验证
1. 表单验证:减轻服务器的压力.保证输入的数据符合要求: 2. 常用的表单验证:日期格式.表单元素是否为空.用户名和密码.E-mail地址.身份证号码等: 3. 表单验证的思路: 1. ...
- All 关键字
本文档已存档,并且将不进行维护. GROUP BY 子句和 ALL 关键字 SQL Server 2005 Transact-SQL 在 GROUP BY 子句中提供 ALL 关键字.只有在 SELE ...
- Centos 7 安装 Haproxy
[环境] Centos 7.2 Web1:192.168.136.170 web2:192.168.136.166 Haproxy:192.168.136.173 [web服务器1.2] 安装Ngin ...
- 禁止打印调用(python)
原文 : https://cloud.tencent.com/developer/ask/188486 import os, sys class HiddenPrints: def __enter__ ...
- 配置Spring Data Redis
事前准备 1.下载redis https://github.com/MicrosoftArchive/redis/releases/tag/win-3.2.100 2.下载redis可视化工具 htt ...
- MongoDB之安装部署
一.安装MongoDB 在安装MongoDB之前,应该先把MongoDB官方网站上下载下来,下载的地址如下: https://www.mongodb.com/download-center 下载完毕之 ...
- Tkinter 之Scale滑块标签
一.参数说明 语法 作用 Scale(window, label="滑块") 滑块标题 Scale(window, label="滑块", from_=0) 滑 ...
- Java核心复习——CompletableFuture
介绍 JDK1.8引入CompletableFuture类. 使用方法 public class CompletableFutureTest { private static ExecutorServ ...