#include<iostream>
using namespace std;
struct Person
{
string name;
string sex;
string id;
int score;
}Temp,Max,Min;
void init()
{
Min.score = 200;
Max.score = 0;
}
//男生成绩最低
bool mGrade(Person temp,Person min)
{
//当前的分数比最低的还要小
if (temp.score != min.score) return temp.score < min.score;
else if (temp.score == min.score) return true;
}
//女生成绩最高
bool fGrade(Person temp, Person max)
{
//当前的分数比最低的还要小
if (temp.score != max.score) return temp.score > max.score;
else return true;
}
void test()
{
int n;
int num1 = 0, num2 = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> Temp.name >> Temp.sex >> Temp.id >> Temp.score;
//先判断是男的
if (Temp.sex == "M")
{
num1 = num1 + 1;
if (mGrade(Temp, Min))
{
//cout << "更新" << endl;
Min = Temp;
}
}
//判断是否为女的
if (Temp.sex == "F")
{
num2 = num2 + 1;
if (fGrade(Temp, Max))
{
//cout << "更新" << endl;
Max = Temp;
}
}
}
int grade = 0;
if (num1 != 0 && num2 != 0)
{
//计算相差
grade = Max.score - Min.score;
}
//输出女生
if (num2 == 0)
{
cout << "Absent" << endl;
}
else {
cout << Max.name << " " << Max.id << endl;
}
//cout << num1;
//男生没有的话
if (num1 == 0)
{
cout << "Absent" << endl;
}
else{
cout << Min.name << " " << Min.id << endl;
}
if (num1 == 0 || num2 == 0)
{
cout << "NA";
}
else
{
cout << grade << endl;
}
}
int main()
{
init();
test();
return 0;
}
【PAT-A1036】 Boys vs Girls (25分)(c++)
最新推荐文章于 2022-11-08 20:55:16 发布