博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1036 Boys vs Girls
阅读量:4540 次
发布时间:2019-06-08

本文共 2482 字,大约阅读时间需要 8 分钟。

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 namegenderID 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
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 int N; 7 struct Node 8 { 9 string name, gender, ID;10 int grade;11 }node;12 int main()13 {14 cin >> N;15 vector
male, female;16 17 //此代码是将数据保存下来排序,还可以直接在输入时就得到最高分和最低分,这样就大大节省了空间和时间18 for (int i = 0; i < N; ++i)19 {20 cin >> node.name >> node.gender >> node.ID >> node.grade;21 if (node.gender == "M")22 male.push_back(node);23 else24 female.push_back(node);25 }26 sort(male.begin(), male.end(), [](Node a, Node b) {
return a.grade < b.grade; });27 sort(female.begin(), female.end(), [](Node a, Node b) {
return a.grade > b.grade; });28 if (female.size() == 0)29 cout << "Absent" << endl;30 else31 cout << female[0].name << " " << female[0].ID << endl;32 if (male.size() == 0)33 cout << "Absent" << endl;34 else35 cout << male[0].name << " " << male[0].ID << endl;36 if (female.size() == 0 || male.size() == 0)37 cout << "NA" << endl;38 else39 cout << female[0].grade - male[0].grade << endl;40 return 0;41 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11256656.html

你可能感兴趣的文章
mysql表操作
查看>>
Flask Web开发从入门到放弃(一)
查看>>
数组的完全随机排列
查看>>
cuda和显卡驱动版本
查看>>
LeetCode OJ
查看>>
你的焦虑迷茫真的不是因为太懒太闲?
查看>>
Autolayout + VFL(Visual Format Language)
查看>>
通过虚拟驱动vivi分析摄像头驱动
查看>>
【JZOJ100208】【20190705】传说之下
查看>>
面试小记
查看>>
线性代数
查看>>
网页设计
查看>>
批量删除空行
查看>>
Java输入
查看>>
Python-ORM之sqlalchemy的简单使用
查看>>
Preserving Remote IP/Host while proxying
查看>>
跟潭州学院的强子老师学习网络爬虫---爬取全书网
查看>>
bzoj千题计划178:bzoj2425: [HAOI2010]计数
查看>>
[国家集训队2012]middle
查看>>
使用Holer远程桌面登录家里电脑和公司内网电脑
查看>>