题目
思路
水题,将男生女生分开存储,分别排序,输出
代码
#include <iostream>
#include <string>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<sstream>
#include<string.h>
#include<math.h>
using namespace std;
#define nmax 20000
#define inf 999999
typedef struct Info
{
string name;
string ID;
int grade;
}Info;
bool cmp1(const Info& a, const Info& b) {
return a.grade < b.grade;
}
bool cmp2(const Info& a, const Info& b) {
return b.grade < a.grade;
}
vector<Info> male;
vector<Info> female;
int main()
{
int num;
cin >> num;
for (int i = 0; i < num; ++i) {
Info info;
char c;
cin >> info.name >> c >> info.ID >> info.grade;
if (c == 'M')
male.push_back(info);
else
female.push_back(info);
}
sort(male.begin(), male.end(), cmp1);
sort(female.begin(), female.end(), cmp2);
if (female.empty())
cout << "Absent" << endl;
else
cout << female[0].name << " " << female[0].ID << endl;
if (male.empty())
cout << "Absent" << endl;
else
cout << male[0].name << " " << male[0].ID << endl;
if (male.empty() || female.empty())
cout << "NA";
else
cout << abs(male[0].grade - female[0].grade);
}