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 ...
随机推荐
- 【动态规划】ZZNU-OJ- 2054 : 油田
2054 : 油田 (一个神奇的功能:点击上方文字进入相应页面) 时间限制:1 Sec 内存限制:32 MiB提交:49 答案正确:6 提交 状态 讨论区 题目描述 在太平洋的一片海域,发现了大量的油 ...
- web上常见的攻击方式及简单的防御方法
SQL注入最常见的攻击方式,所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令,比如先前的很多影视网站泄露VIP会员密码大 ...
- C#获取资源文件
System.Resources.ResourceManager rs = new System.Resources.ResourceManager("NetWebBrowser.Resou ...
- c语言之——整型的隐式转换与溢出检测
溢出检测 我们可以通过下面的方式来检测溢出: if(a > INT_MAX - b) { printf("overflow\n"); } 我们利用整型的最大值减去其中 ...
- python - scrapy 爬虫框架 ( redis去重 )
1. 使用内置,并加以修改 ( 自定义 redis 存储的 keys ) settings 配置 # ############### scrapy redis连接 ################# ...
- windows nginx 搭建文件服务器(通俗易懂)
在一些项目里面,有时候需要访问图片的时候.相信很多人都是的直接把文件放到项目里面的: 今天在这里给大家介绍的是利用nginx 搭建图片服务器,直接访问磁盘上的图片. 方法一(使用root关键字): l ...
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A,B,C【真的菜·】
8说了 #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string s ...
- 学到了林海峰,武沛齐讲的Day20 装饰器
import time def timmer(func): #func=test 装饰器架构 def wrapper(): start_time=time.time() func() #就是在运行te ...
- 42 | grant之后要跟着flush privileges吗?
在 MySQL 里面,grant 语句是用来给用户赋权的.不知道你有没有见过一些操作文档里面提到,grant 之后要马上跟着执行一个 flush privileges 命令,才能使赋权语句生效.我最开 ...
- Oracle 11g 禁用 SQL Tuning Advisor 与 auto space advisor
生产上有一套11g数据库alert.log报错ORA-16957: SQL Analyze time limit interrupt. 查询MOS相关文档Troubleshooting: ORA-1 ...