【PAT】【Advanced Level】1036. Boys vs Girls (25)
来源:互联网 发布:风速打印软件 编辑:程序博客网 时间:2024/06/05 11:10
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 95Sample Output 1:
Mary EE990830Joe Math9901126Sample Input 2:
1Jean M AA980920 60Sample Output 2:
AbsentJean AA980920NA
https://www.patest.cn/contests/pat-a-practise/1036
思路:
边读入边筛选
CODE:
#include<iostream>#include<cstring>#include<string>using namespace std;int main(){ int n; cin>>n; int mg=101; int fg=-1; string mn; string fn; string ms; string fs; for (int i=0;i<n;i++) { string a,b,c; int d; cin>>a>>b>>c>>d; if (b=="F") { if (d>fg) { fg=d; fn=a; fs=c; } } else { if (d<mg) { mg=d; mn=a; ms=c; } } } if (fg==-1) { cout<<"Absent"<<endl; } else { cout<<fn<<" "<<fs<<endl; } if (mg==101) { cout<<"Absent"<<endl; } else { cout<<mn<<" "<<ms<<endl; } if (fg==-1||mg==101) { cout<<"NA"<<endl; } else { cout<<fg-mg<<endl; } return 0;}
- 【C++】PAT(advanced level)1036. Boys vs Girls (25)
- 【PAT (Advanced Level)】1036. Boys vs Girls (25)
- PAT (Advanced Level) 1036. Boys vs Girls (25) 解题报告
- 【PAT】【Advanced Level】1036. Boys vs Girls (25)
- PAT (Advanced Level) Practise 1036 Boys vs Girls (25)
- PAT (Advanced Level) Practise 1036 Boys vs Girls (25)
- PAT (Advanced Level) 1036. Boys vs Girls (25) 结构体排序
- 1036. Boys vs Girls (25)【水题】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1036(Boys vs Girls))
- 1036. Boys vs Girls (25)-PAT
- 【PAT】1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- PAT A 1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- pat 1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- PAT甲级.1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25) PAT 甲级
- LeetCode136 Single Number
- Java多线程基础--08之 join()
- Unity_相机跟随效果_052
- python对象身份的比较
- 【DSP】TMS320F28035 ADC例程(ePWM+中断)
- 【PAT】【Advanced Level】1036. Boys vs Girls (25)
- Anagrams变位词
- 神经网络与深度学习 1.6 使用Python实现基于梯度下降算法的神经网络和MNIST数据集的手写数字分类程序
- 开发微信小程序:工具准备和发布流程
- 换电脑,重新布置环境
- jquery的总体架构分析及实现示例详解
- R语言画不全词云图问题
- JavaScript中this的指向
- C++之明智审慎地使用private继承(39)---《Effective C++》