1036. Boys vs Girls (25)
2015-12-06 10:42
417 查看
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:
来源: <http://www.patest.cn/contests/pat-a-practise/1036>
[/code]
来自为知笔记(Wiz)
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 95Sample Output 1:[/b]
Mary EE990830 Joe Math990112 6Sample Input 2:[/b]
1 Jean M AA980920 60Sample Output 2:[/b]
Absent Jean AA980920 NA
来源: <http://www.patest.cn/contests/pat-a-practise/1036>
#pragma warning(disable:4996)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct Stu
{
string name;
char gender;
string ID;
int grade;
};
vector<Stu> boys, girls;
bool cmp1(Stu a, Stu b) {
return a.grade < b.grade;
}
bool cmp2(Stu a, Stu b) {
return a.grade > b.grade;
}
int main(void) {
int n;
cin >> n;
boys.clear();
girls.clear();
for (int i = 0; i < n; i++) {
Stu temp;
cin >> temp.name >> temp.gender >> temp.ID >> temp.grade;
if (temp.gender == 'M')
boys.push_back(temp);
else
girls.push_back(temp);
}
if (boys.empty() == true) {
sort(girls.begin(), girls.end(), cmp2);
cout << girls[0].name << " "<<girls[0].ID << endl;
cout << "Absent" << endl;
cout << "NA";
}
else if (girls.empty() == true) {
cout << "Absent" << endl;
sort(boys.begin(), boys.end(), cmp1);
cout << boys[0].name << " " << boys[0].ID << endl;
cout << "NA";
}
else {
sort(girls.begin(), girls.end(), cmp2);
cout << girls[0].name << " " << girls[0].ID << endl;
sort(boys.begin(), boys.end(), cmp1);
cout << boys[0].name << " " << boys[0].ID << endl;
cout << (girls[0].grade - boys[0].grade);
}
return 0;
}
[/code]
来自为知笔记(Wiz)
相关文章推荐
- USART---串口发送数据
- C# explicit与implicit
- 1035. Password (20)
- javascript字符串函数汇总
- C中qsort的补局限和C++中sort的用法
- IP地址
- 【Html】caption标签,为表格添加标题和摘要
- 1034. Head of a Gang (30)
- 1033. To Fill or Not to Fill (25)
- matlab function与script文件的区别
- n皇后问题
- Hive ORC文件格式存储与测试(Malformed ORC file解决)
- 某去网的mapreduce面试题
- 最优布线问题
- Java学习笔记(集合_1)
- C#基础篇一
- 关于Keil的安装与注册
- VCS filelist 文件格式
- 微信学习系列之一:定时获取微信access_token的线程
- 最短路径问题