#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
struct Student
{
string id;
int c, m, e, a;
int rank[4];// a, c, m, e
};
vector<Student> student;
bool cmp_c(const Student &a, const Student &b)
{
return a.c > b.c;
}
bool cmp_m(const Student &a, const Student &b)
{
return a.m > b.m;
}
bool cmp_e(const Student &a, const Student &b)
{
return a.e > b.e;
}
bool cmp_a(const Student &a, const Student &b)
{
return a.a > b.a;
}
int main()
{
// freopen("in.txt", "r", stdin);
int N, M;
cin >> N >> M;
Student stu;
for (int i = 0; i < N; i++)
{
cin >> stu.id >> stu.c >> stu.m >> stu.e;
stu.a = stu.c + stu.m + stu.e;
student.push_back(stu);
}
sort(student.begin(), student.end(), cmp_a);
student[0].rank[0] = 0;
for (int i = 0; i < N - 1; i++)
{
if (student[i + 1].a == student[i].a)
student[i + 1].rank[0] = student[i].rank[0];
else
student[i + 1].rank[0] = i + 1;
}
sort(student.begin(), student.end(), cmp_c);
student[0].rank[1] = 0;
for (int i = 0; i < N - 1; i++)
{
if (student[i + 1].c == student[i].c)
student[i + 1].rank[1] = student[i].rank[1];
else
student[i + 1].rank[1] = i + 1;
}
sort(student.begin(), student.end(), cmp_m);
student[0].rank[2] = 0;
for (int i = 0; i < N - 1; i++)
{
if (student[i + 1].m == student[i].m)
student[i + 1].rank[2] = student[i].rank[2];
else
student[i + 1].rank[2] = i + 1;
}
sort(student.begin(), student.end(), cmp_e);
student[0].rank[3] = 0;
for (int i = 0; i < N - 1; i++)
{
if (student[i + 1].e == student[i].e)
student[i + 1].rank[3] = student[i].rank[3];
else
student[i + 1].rank[3] = i + 1;
}
vector<string> toreq;
string tmp;
for (int i = 0; i < M; i++)
{
cin >> tmp;
toreq.push_back(tmp);
}
int pos, min;
for (int i = 0; i < M; i++)
{
bool flag = false;
for (int j = 0; j < N; j++)
{
if (student[j].id == toreq[i])
{
flag = true;
min = student[j].rank[0];
pos = 0;
for (int k = 1; k < 4; k++)
{
if (min > student[j].rank[k])
{
min = student[j].rank[k];
pos = k;
}
}
break;
}
}
if (!flag)
cout << "N/A" << endl;
else
{
cout << min + 1 << " ";
switch (pos)
{
case 0:
cout << "A";
break;
case 1:
cout << "C";
break;
case 2:
cout << "M";
break;
case 3:
cout << "E";
break;
}
cout << endl;
}
}
}
PAT (Advanced) 1012. The Best Rank (25)
最新推荐文章于 2023-08-10 12:46:07 发布