本文代码来源为此处
//1012. The Best Rank(25) #include #include #include #include using namespace std; struct stu { int ID; int C; int M; int E; int A; int bestRank; char bestItem; stu(int id, int c, int m, int e) :ID(id), C(c), M(m), E(e) { A = (c + m + e) / 3; } }; bool compA(stu s1, stu s2) { return s1.A>s2.A; } bool compC(stu s1, stu s2) { return s1.C>s2.C; } bool compM(stu s1, stu s2) { return s1.M>s2.M; } bool compE(stu s1, stu s2) { return s1.E>s2.E; } int main() { int N, M; cin >> N >> M; if (N == 0) { int x; while (M--) { cin >> x; cout << "N/A" << endl; } return 0; } int id, c, m, e; vector students; for (int i = 0; i> id >> c >> m >> e; students.push_back(stu(id, c, m, e)); } sort(students.begin(), students.end(), compA); int rankA = 1; students[0].bestRank = 1; students[0].bestItem = 'A'; for (int i = 1; i map;//用于查询 for (int i = 0; i> x; if (map.find(x) == map.end())//感觉很好用的样子 cout << "N/A" << endl; else cout << students[map[x]].bestRank << " " << students[map[x]].bestItem << endl; } return 0; }
回忆知识点:
1、结构体
2、构造函数
3、sort函数
4、vector
新知识点:
map
参考此处