To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input Specification:
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.
Output Specification:
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output N/A.
Sample Input:
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
结尾无空行
Sample Output:
1 C
1 M
1 E
1 A
3 A
N/A
结尾无空行
也就只有 天梯或者 pta 出这种 jb 题了,要是面试,不可能考着样的,md。
测试点二不过的原因是,如果存在分数相同,那么排名也应该是相同的,比如 1 1 3 4 5,这个时候就要注意更新的问题了,如果按照我这个方法,结构体中 rank 存的就是最好的结果,那么 如果分数相同,就不能设置为前一个人的排名了,而是得设置 t
相同排名的问题真的搞了我好久
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cctype>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<cstring>
using namespace std;
const int N = 2001;
struct Person {
string id;
int c;
int m;
int e;
int a;
int rank = 2002;
char Rank;
} P[N];
bool cmp1(Person i, Person j) {
if (i.a == j.a) {
if (i.c == j.c) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
return i.c > j.c;
}
return i.a > j.a;
}
bool cmp2(Person i, Person j) {
if (i.c == j.c) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
return i.c > j.c;
}
bool cmp3(Person i, Person j) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
bool cmp4(Person i, Person j) {
return i.e > j.e;
}
set<string> st;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> P[i].id >> P[i].c >> P[i].m >> P[i].e;
P[i].a = (int)((P[i].c + P[i].m + P[i].e) / 3.0 + 0.5);
st.insert(P[i].id);
}
int t = 1;
sort(P, P + n, cmp1);
for (int i = 0; i < n; i++) {
if (i == 0) {
P[i].rank = t;
P[i].Rank = 'A';
} else {
if (P[i].a != P[i - 1].a) {
t = i + 1;
}
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'A';
}
}
}
t = 1;
sort(P, P + n, cmp2);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'C';
}
} else {
if (P[i].c != P[i - 1].c) {
t = i + 1;
}
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'C';
}
}
}
t = 1;
sort(P, P + n, cmp3);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'M';
}
} else {
if (P[i].m != P[i - 1].m) {
t = i + 1;
}
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'M';
}
}
}
t = 1;
sort(P, P + n, cmp4);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'E';
}
} else {
if (P[i].e != P[i - 1].e) {
t = i + 1;
}
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'E';
}
}
}
while (m--) {
string s;
cin >> s;
if (!st.count(s)) {
cout << "N/A" << endl;
} else {
for (int i = 0; i < n; i++) {
if (P[i].id == s) {
cout << P[i].rank << " " << P[i].Rank << endl;
}
}
}
}
}
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cctype>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<cstring>
using namespace std;
const int N = 2001;
struct Person {
string id;
int c;
int m;
int e;
int a;
int rank = 2002;
char Rank;
} P[N];
bool cmp1(Person i, Person j) {
if (i.a == j.a) {
if (i.c == j.c) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
return i.c > j.c;
}
return i.a > j.a;
}
bool cmp2(Person i, Person j) {
if (i.c == j.c) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
return i.c > j.c;
}
bool cmp3(Person i, Person j) {
if (i.m == j.m) {
return i.e > j.e;
}
return i.m > j.m;
}
bool cmp4(Person i, Person j) {
return i.e > j.e;
}
set<string> st;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> P[i].id >> P[i].c >> P[i].m >> P[i].e;
P[i].a = (int)((P[i].c + P[i].m + P[i].e) / 3.0 + 0.5);
st.insert(P[i].id);
}
int t = 1;
sort(P, P + n, cmp1);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'A';
}
} else {
if (P[i].a == P[i - 1].a) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'A';
}
} else {
t = i + 1;
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'A';
}
}
}
}
t = 1;
sort(P, P + n, cmp2);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'C';
}
} else {
if (P[i].c == P[i - 1].c) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'C';
}
} else {
if (P[i].rank > i + 1) {
P[i].rank = i + 1;
P[i].Rank = 'C';
}
t = i + 1;
}
}
}
t = 1;
sort(P, P + n, cmp3);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'M';
}
} else {
if (P[i].m == P[i - 1].m) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'M';
}
} else {
if (P[i].rank > i + 1) {
P[i].rank = i + 1;
P[i].Rank = 'M';
}
t = i + 1;
}
}
}
t = 1;
sort(P, P + n, cmp4);
for (int i = 0; i < n; i++) {
if (i == 0) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'E';
}
} else {
if (P[i].e == P[i - 1].e) {
if (P[i].rank > t) {
P[i].rank = t;
P[i].Rank = 'E';
}
} else {
if (P[i].rank > i + 1) {
P[i].rank = i + 1;
P[i].Rank = 'E';
}
t = i + 1;
}
}
}
while (m--) {
string s;
cin >> s;
if (!st.count(s)) {
cout << "N/A" << endl;
} else {
for (int i = 0; i < n; i++) {
if (P[i].id == s) {
cout << P[i].rank << " " << P[i].Rank << endl;
}
}
}
}
}