PAT A1036
来源:互联网 发布:支持绑定第三方域名 编辑:程序博客网 时间:2024/05/21 08:02
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:
3Joe M Math990112 89Mike M CS991301 100Mary F EE990830 95
Sample Output 1:Mary EE990830Joe Math9901126
Sample Input 2:1Jean M AA980920 60
Sample Output 2:AbsentJean AA980920NA
#include <iostream>using namespace std;struct Student{ string name; string id; int score;}girl, boy, temp;void init(){ girl.name = " "; girl.id = " "; girl.score = 0; boy.name = " "; boy.id = " "; boy.score = 105;}void firstgirl(struct Student a){ if(girl.score < a.score){ girl.name = a.name; girl.id = a.id; girl.score = a.score; }}void boylast(struct Student a){ if(boy.score > a.score){ boy.name = a.name; boy.id = a.id; boy.score = a.score; }}int main(){ init(); int N; char ch; cin>>N; while(N--){ cin>>temp.name>>ch>>temp.id>>temp.score; if(ch == 'F'){ firstgirl(temp); } if(ch == 'M'){ boylast(temp); } } if(girl.name == " "){ cout<<"Absent"<<endl; if(boy.name == " "){ cout<<"Absent"<<endl; cout<<"NA"<<endl; }else{ cout<<boy.name<<" "<<boy.id<<endl; cout<<"NA"<<endl; } }else{ cout<<girl.name<<" "<<girl.id<<endl; if(boy.name == " "){ cout<<"Absent"<<endl; cout<<"NA"<<endl; }else{ cout<<boy.name<<" "<<boy.id<<endl; cout<<(girl.score - boy.score)<<endl; } }}
- [PAT] A1036
- PAT A1036
- PAT-A1036
- PAT a1036题解
- A1036
- 【PAT】A1036. Boys vs Girls (25)
- PAT A1036. Boys vs Girls (25)
- PAT-A1036 Boys vs Girls(25) (模拟)
- A1036 Boys vs Girls
- tsinsen A1036. 分解质因数
- A1036. 分解质因数
- 清澄A1036. 分解质因数
- A1036. Boys vs Girls (25)
- 刷清橙OJ--A1036.分解质因数
- 清橙OJ A1036.分解质因数
- pat
- 【PAT】
- PAT
- 前后端分离架构中的接口设计
- Linux 系统启动过程
- 如何使应用程序只运行一个实例
- MatConvnet工具箱文档翻译理解一
- 需求分析
- PAT A1036
- 幸福的道路(race) ssl 2570 bzoj 2500 单调队列
- 大龄程序员的发展方向是做管理还是继续写程序?
- Hibernate二级缓存
- UBUNTU如何修改IP
- 七种CSS方式让一个容器水平垂直居中
- 火狐浏览器flash插件经常崩溃解决办法
- java多线程学习(三)
- Linux冬瓜皮(DNS)