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.
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".
5 6<br/>310101 98 85 88<br/>310102 70 95 88<br/>310103 82 87 94<br/>310104 91 91 91<br/>310105 85 90 90<br/>310101<br/>310102<br/>310103<br/>310104<br/>310105<br/>999999
1 C<br/>1 M<br/>1 E<br/>1 A<br/>3 A<br/>N/A
1.ID必须是字符串类型,不能用整数存。
2.求平均分时直接向下取整,而不是四舍五入。
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<algorithm> #include<unordered_map> using namespace std; int w = 0; struct stu{ string id; int c, m, e, a; int cc, mm, ee, aa; //排名 }E[2005]; bool cmp(stu a, stu b){ if (w == 0) return a.a > b.a; else if(w == 1) return a.c > b.c; else if(w == 2) return a.m > b.m; else return a.e > b.e; } void print(int x){ char ch = 'A'; int d = E[x].aa; if(d > E[x].cc) d = E[x].cc, ch = 'C'; if(d > E[x].mm) d = E[x].mm, ch = 'M'; if(d > E[x].ee) d = E[x].ee, ch = 'E'; cout<<d<<" "<<ch<<endl; } int main(){ int n, m, x; string s; unordered_map<string, int> mp; cin >> n >> m; for(int i = 0; i < n; i++){ cin>>E[i].id >>E[i].c >> E[i].m>>E[i].e; E[i].a = (E[i].c + E[i].m + E[i].e)/3.0; } sort(E, E + n, cmp); for(int i = 0 ; i < n; i++){ //相同成绩相同排名 if(i > 0 && E[i-1].a == E[i].a) E[i].aa = E[i-1].aa; else E[i].aa = i + 1; } w=1; sort(E, E + n, cmp); for(int i = 0 ; i < n; i++){ if(i > 0 && E[i-1].c == E[i].c) E[i].cc = E[i-1].cc; else E[i].cc = i + 1; } w=2; sort(E, E + n, cmp); for(int i = 0 ; i < n; i++){ if(i > 0 && E[i-1].m == E[i].m) E[i].mm = E[i-1].mm; else E[i].mm = i + 1; } w=3; sort(E, E + n, cmp); for(int i = 0 ; i < n; i++){ if(i > 0 && E[i-1].e == E[i].e) E[i].ee = E[i-1].ee; else E[i].ee = i + 1; mp[E[i].id] = i + 1; } while(m--){ cin >> s; if(!mp[s]) cout<<"N/A"<<endl; else{ print(mp[s] - 1); } } return 0; }
#include <cstdio> #include <algorithm> using namespace std; struct student{ int id; int score[4]; //存放4个分数 }s[2010]; int Rank[10000000][4]={0}; //Rank[id][0]到Rank[id][3] 为4门课对应的排名 int q; //在cmp函数中使用,表示当前按p号分数排序s数组 bool cmp(student a,student b){ return a.score[q]>b.score[q]; //s数组按p号分数递减排序 } char course[4]={'A','C','M','E'}; //按每科优先级顺序,方便输出 int main(int argc, char *argv[]){ int x,y;int p; scanf("%d%d",&x,&y); //x为要排序的人数,y为要查询的人数 for(int i=0;i<x;i++){ scanf("%d%d%d%d",&s[i].id,&s[i].score[1],&s[i].score[2],&s[i].score[3]); //输入3科分数,并求出平均分(这里直接用总分代替) s[i].score[0]=s[i].score[1]+s[i].score[2]+s[i].score[3]; } for(q=0;q<4;q++){ //3科加平均分都排名一次 sort(s,s+x,cmp); Rank[s[0].id][q]=1; //将排名后的第一个元素名次设为1(直接赋值给id所在位置) for(int j=1;j<x;j++){ if(s[j].score[q]==s[j-1].score[q]) //如果跟前一个元素一样的分数,则有一样的排名 Rank[s[j].id][q]=Rank[s[j-1].id][q]; else Rank[s[j].id][q]=j+1; //跟前一个元素不一样的分数,则排名为下标加1 } } for(int i=0;i<y;i++){ scanf("%d",&p); //输入查询的id if(Rank[p][0]==0) printf("N/A\n"); //该id不存在 else{ int num=0; for(int k=0;k<4;k++){ //求出该名学生4科中排名最前的一科 if(Rank[p][k]<Rank[p][num]) num=k; } printf("%d %c\n",Rank[p][num],course[num]); } } return 0; }
#include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct stu2
{
char id[10];
double c_score,m_score,e_score,a_score;
int c_rank,m_rank,e_rank,a_rank;
};
int cmpC(stu2 a,stu2 b)
{
return a.c_score>b.c_score;
}
int cmpA(stu2 a,stu2 b)
{
return a.a_score>b.a_score;
}
int cmpM(stu2 a,stu2 b)
{
return a.m_score>b.m_score;
}
int cmpE(stu2 a,stu2 b)
{
return a.e_score>b.e_score;
}
void sortStu(stu2 *input,int N)
{
//a
sort(input,input+N,cmpA);
for(int i =0;i<N;i++)
{
if(i>0&&input[i].a_score==input[i-1].a_score)
input[i].a_rank=input[i-1].a_rank;
else
input[i].a_rank=i+1;
}
//c
sort(input,input+N,cmpC);
for(int i =0;i<N;i++)
{
if(i>0&&input[i].c_score==input[i-1].c_score)
input[i].c_rank=input[i-1].c_rank;
else
input[i].c_rank=i+1;
}
//m
sort(input,input+N,cmpM);
for(int i =0;i<N;i++)
{
if(i>0&&input[i].m_score==input[i-1].m_score)
input[i].m_rank=input[i-1].m_rank;
else
input[i].m_rank=i+1;
}
//e
sort(input,input+N,cmpE);
for(int i =0;i<N;i++)
{
if(i>0&&input[i].e_score==input[i-1].e_score)
input[i].e_rank=input[i-1].e_rank;
else
input[i].e_rank=i+1;
}
/*for(int i =0;i<N;i++)
{
cout<<input[i].id<<" - "<<input[i].c_rank<<endl;
}*/
};
void getBestRank(stu2 stu)
{
if(stu.a_rank<=stu.c_rank&&stu.a_rank<=stu.m_rank&&stu.a_rank<=stu.e_rank)
{
//a
cout<<stu.a_rank<<" A"<<endl;
}else if(stu.c_rank<=stu.a_rank&&stu.c_rank<=stu.m_rank&&stu.c_rank<=stu.e_rank)
{
//c
cout<<stu.c_rank<<" C"<<endl;
}else if(stu.m_rank<=stu.a_rank&&stu.m_rank<=stu.c_rank&&stu.m_rank<=stu.e_rank)
{
//m
cout<<stu.m_rank<<" M"<<endl;
}else
{
//e
cout<<stu.e_rank<<" E"<<endl;
}
};
void calBestRank(stu2 *input,char toFind[10],int N)
{
for(int i=0;i<N;i++)
{
if(strcmp(input[i].id,toFind)==0)
{
//输出最好的排名A>C>M>E
getBestRank(input[i]);
return;
}
}
cout<<"N/A"<<endl;
};
int main()
{
int N,M;
scanf("%d %d",&N,&M);
stu2 *input = new stu2[N];
for(int i=0;i<N;i++)
{
stu2 tmp;
scanf("%s %lf %lf %lf",tmp.id,&tmp.c_score,&tmp.m_score,&tmp.e_score);
tmp.a_score = (tmp.c_score+tmp.m_score+tmp.e_score)/3;
input[i] = tmp;
//cout<<tmp.id;
}
//sort
sortStu(input,N);
for(int i=0;i<M;i++)
{
char tmp[10];
scanf("%s",tmp);
calBestRank(input,tmp,N);
}
return 0;
}
#include <iostream> #include <map> #include <vector> #include <string> using namespace std; map<string, map<int, vector<char>>> database; map<int, vector<string>, greater<int>> math; map<int, vector<string>, greater<int>> cprogramming; map<int, vector<string>, greater<int>> english; map<int, vector<string>, greater<int>> average; int main(){ int n; int m; cin >> n; cin >> m; string id; int mathGrade; int cprogrammingGrade; int englishGrade; for(int i = 0; i < n; i++){ cin >> id; cin >> cprogrammingGrade; cin >> mathGrade; cin >> englishGrade; cprogramming[cprogrammingGrade].push_back(id); math[mathGrade].push_back(id); english[englishGrade].push_back(id); int averageGrade = (mathGrade + cprogrammingGrade + englishGrade) / 3; average[averageGrade].push_back(id); } int count = 1; for(map<int, vector<string>>::iterator it = average.begin(); it != average.end(); ++it){ int tieCount = 0; for(vector<string>::iterator itr = it->second.begin(); itr != it->second.end(); ++itr){ database[*itr][count].push_back('A'); //cout << "push A=" << it->first << "at" << distance(average.begin(), it) + 1 << endl; tieCount++; } count += tieCount; } count = 1; for(map<int, vector<string>>::iterator it = cprogramming.begin(); it != cprogramming.end(); ++it){ int tieCount = 0; for(vector<string>::iterator itr = it->second.begin(); itr != it->second.end(); ++itr){ database[*itr][count].push_back('C'); tieCount++; } count += tieCount; } count = 1; for(map<int, vector<string>>::iterator it = math.begin(); it != math.end(); ++it){ int tieCount = 0; for(vector<string>::iterator itr = it->second.begin(); itr != it->second.end(); ++itr){ database[*itr][count].push_back('M'); tieCount++; } count += tieCount; } count = 1; for(map<int, vector<string>>::iterator it = english.begin(); it != english.end(); ++it){ int tieCount = 0; for(vector<string>::iterator itr = it->second.begin(); itr != it->second.end(); ++itr){ database[*itr][count].push_back('E'); tieCount++; } count += tieCount; } for(int i = 0; i < m; i++){ cin >> id; if(database.count(id)){ cout << database[id].begin()->first << " " << database[id].begin()->second[0] << endl; }else{ cout << "N/A" << endl; } } return 0; }
#include<cstdio> #include<iostream> #include<vector> #include<unordered_map> #include<string> #include<algorithm> using namespace std; #define MAX 2010 struct Student { int grade[4]; int rank[4]; }; int N, M; Student stu[MAX]; string outname[MAX]; unordered_map<string, Student> mp; bool cmp(int a, int b) { return a > b; } int getRank(int grade, vector<int>& list) //二分 { int a = 0, b = N - 1, t = 0; while (grade != list[t]) { t = (a + b) / 2; if (grade < list[t]) a = t + 1; else if (grade > list[t]) b = t - 1; } while (t > 0 && list[t - 1] == list[t]) { t--; } return t + 1; //返回的是下标,要转成排名 } int main() { scanf("%d %d", &N, &M); int i, j, t, sum; string name; vector<int> ranklist[4]; //维护四个科目总排名 for (i = 0; i < N; i++) { cin >> name; sum = 0; for (j = 1; j < 4; j++) { scanf("%d", &t); sum += t; stu[i].grade[j] = t; ranklist[j].push_back(t); //建立成绩表 } stu[i].grade[0] = sum; ranklist[0].push_back(sum); mp[name] = stu[i]; } for (i = 0; i < 4; i++) sort(ranklist[i].begin(), ranklist[i].end(), cmp); for (i = 0; i < M; i++) cin >> outname[i]; int gbest; char cbest; for (i = 0; i < M; i++) { if (mp.find(outname[i]) != mp.end()) { for (j = 0; j < 4; j++) { mp[outname[i]].rank[j] = getRank(mp[outname[i]].grade[j], ranklist[j]); if (j == 0) { gbest = mp[outname[i]].rank[j]; cbest = 'A'; } else if (gbest > mp[outname[i]].rank[j]) //排名越小越好 { gbest = mp[outname[i]].rank[j]; if (j == 1) cbest = 'C'; else if (j == 2) cbest = 'M'; else if (j == 3) cbest = 'E'; } } printf("%d %c\n", gbest, cbest); } else { //没找到 printf("N/A\n"); } } return 0; }
#include<bits/stdc++.h> using namespace std; int tag; int C = 0,M =1,E = 2, A= 3, CR =4, MR=5, ER=6, AR=7; bool cmp(pair<string,vector<int>>& a, pair<string,vector<int>>& b) { return (a.second[tag] > b.second[tag]); } int main() { int m, n; cin>>n>>m; vector<pair<string,vector<int>>> db; unordered_map<string, char> hashmap; while (n--) { pair<string, vector<int>> mp; string id; int a,b,c,d; cin>>id>>a>>b>>c; mp.first = id; d = (a+b+c) / 3; mp.second = {a,b,c,d,0,0,0,0}; db.emplace_back(mp); hashmap[id]++; } for (tag = 0; tag < 4; tag++) { sort(db.begin(), db.end(), cmp); for (int i = 0; i < db.size(); i++) { if (i > 0 && db[i].second[tag] == db[i - 1].second[tag]){ db[i].second[tag + 4] = db[i - 1].second[tag + 4]; }else db[i].second[tag + 4] = i+1; } } while (m--) { string id; cin>>id; if (hashmap.find(id) == hashmap.end()) { cout<<"N/A"<<endl; } else { for (auto& t:db) { if (t.first == id) { if (t.second[AR] <= t.second[MR] && t.second[AR] <= t.second[ER] && t.second[AR] <= t.second[CR]) { cout<<t.second[AR]<<" "<<"A"<<endl; } else if (t.second[CR] <= t.second[MR] && t.second[CR] <= t.second[ER] && t.second[CR] <= t.second[AR]) { cout<<t.second[CR]<<" "<<"C"<<endl; } else if (t.second[MR] <= t.second[AR] && t.second[MR] <= t.second[ER] && t.second[MR] <= t.second[CR]) { cout<<t.second[MR]<<" "<<"M"<<endl; } else if(t.second[ER] <= t.second[MR] && t.second[ER] <= t.second[AR] && t.second[ER] <= t.second[CR]) { cout<<t.second[ER]<<" "<<"E"<<endl; } break; } } } } return 0;
a = list(map(int,input().split())) d,m,n,o,p,q ={},[],[],[],[],['A','C','M','E'] for i in range(a[0]): b = input().split() d[b[0]] = i m.append(sum(map(int,b[1:]))) for j in range(1,4): eval(chr(109 + j)).append(int(b[j])) q = ['A','C','M','E'] for i in range(a[1]): b = input() if b in d: s = a[0] for j in range(4): r = len(list(filter(lambda x:x > eval(chr(109 + j))[d[b]],eval(chr(109 + j))))) + 1 if r < s: s,t = r,q[j] print(s,t) else: print('N/A')
#include<iostream> #include<string.h> #include<algorithm> using namespace std; int main(){ string s[2005],h[2005]; int c[2005],m[2005],e[2005],a[2005]; int cp[2005],mp[2005],ep[2005],ap[2005]; memset(cp,1,sizeof(cp)); memset(mp,1,sizeof(mp)); memset(ep,1,sizeof(ep)); memset(ap,1,sizeof(ap)); char nn[4]={'A','C','M','E'}; int n,k,i,j,d; int maxx=0; int t=0; cin >> n >> k; for(i=0;i<n;i++){ cin >> s[i] >> c[i] >> m[i] >> e[i]; } for(j=0;j<k;j++){ cin >> h[j]; } for(i=0;i<n;i++){ a[i]=(c[i]+m[i]+e[i])/3; } if(n==1){ cout << "1" <<" " << "A" <<endl; } else{ for(i=0;i<n;i++){ t=1; for(j=0;j<n;j++){ if(c[j]>c[i]){ t++; } } cp[i]=t; } for(i=0;i<n;i++){ t=1; for(j=0;j<n;j++){ if(a[j]>a[i]){ t++; } } ap[i]=t; } for(i=0;i<n;i++){ t=1; for(j=0;j<n;j++){ if(m[j]>m[i]){ t++; } } mp[i]=t; } for(i=0;i<n;i++){ t=1; for(j=0;j<n;j++){ if(e[j]>e[i]){ t++; } } ep[i]=t; } //cout << cp[0] <<" "<< ap[0] <<" "<< ep[0] <<" "<< mp[0]; int res[5]; int temp; for(i=0;i<k;i++){ int r=0; for(j=0;j<n;j++){ if(h[i]==s[j]){ r++; res[0]=ap[j]; res[1]=cp[j]; res[2]=mp[j]; res[3]=ep[j]; int minn=n; for(d=0;d<4;d++){ if(minn>res[d]){ minn=res[d]; temp=d; } } cout << minn << " " << nn[temp]<<endl; } } if(r==0){ cout << "N/A" <<endl; } }} }
g1,g2,g3,g4 = [],[],[],[] stu = {} n,m = map(int,input().split()) for i in range(n): t = input().split() # stu[t[0]]=[(int(t[1])+int(t[2])+int(t[3]))//3,int(t[1]),int(t[2]),int(t[3])] g1.append([t[0],(int(t[1])+int(t[2])+int(t[3]))//3]) g2.append([t[0],int(t[1])]) g3.append([t[0],int(t[2])]) g4.append([t[0],int(t[3])]) g1.sort(key = lambda x:(-x[1])) g2.sort(key = lambda x:(-x[1])) g3.sort(key = lambda x:(-x[1])) g4.sort(key = lambda x:(-x[1])) con = 1 stu[g1[0][0]],temp = [con,'A'],g1[0][1] for i in range(1,n): if g1[i][1]==temp: stu[g1[i][0]] = [con,'A'] else: con = i+1 temp = g1[i][1] stu[g1[i][0]] = [con,'A'] con = 1 temp = g2[0][1] if stu[g2[0][0]][0]>con: stu[g2[0][0]] = [con,'C'] for i in range(1,n): if g2[i][1]==temp: if stu[g2[i][0]][0]>con: stu[g2[i][0]] = [con,'C'] else: con = i+1 temp = g2[i][1] if stu[g2[i][0]][0]>con: stu[g2[i][0]] = [con,'C'] con = 1 temp = g3[0][1] if stu[g3[0][0]][0]>con: stu[g3[0][0]] = [con,'M'] for i in range(1,n): if g3[i][1]==temp: if stu[g3[i][0]][0]>con: stu[g3[i][0]] = [con,'M'] else: con = i+1 temp = g3[i][1] if stu[g3[i][0]][0]>con: stu[g3[i][0]] = [con,'M'] con = 1 temp = g4[0][1] if stu[g4[0][0]][0]>con: stu[g4[0][0]] = [con,'E'] for i in range(1,n): if g4[i][1]==temp: if stu[g4[i][0]][0]>con: stu[g4[i][0]] = [con,'E'] else: con = i+1 temp = g4[i][1] if stu[g4[i][0]][0]>con: stu[g4[i][0]] = [con,'E'] for j in range(m): query = input() if query not in stu: print("N/A") else: print(str(stu[query][0])+" "+stu[query][1])这道题本来是一道水题,但是由于排名的规则没有说清楚,调代码也是调的让人头大。而且,个人觉得该题目也要说清楚平均分得出的是取整还是四舍五入还是可保留小数位的。如果能说清楚的话会省去不少调试带来的烦恼。
思路:使用类的方法处理 注意点,根据上面大佬所讲,首先 平均数,是整数,注意。然后没有然后了。 #include <iostream> #include <map> #include <vector> #include <string> #include <fstream> #include <algorithm> using namespace std; #ifndef debug ifstream ifile("case.txt"); #define cin ifile #endif int priorities[4] = { 1,2,3,4 }; const string strRankNam[] = { "A","C","M","E" }; class student { public: string name; int C; int M; int E; int A; int rank[4] = {0};// A C M E //string bestRank; public: void BestRank() { int minRank = 0; for (int i = 1; i < 4; i++) { if (rank[minRank] > rank[i]) { minRank = i; } else if (rank[minRank] == rank[i] && rank[minRank] * priorities[minRank] > rank[i] * priorities[i]) { minRank = i; } } cout << rank[minRank] << " " << strRankNam[minRank] << endl; } void Avg() { this->A = (this->C + this->E + this->M) / 3; } }; bool Cmp1(student &a, student &b)// 平均分排名 { return a.A > b.A; } bool Cmp2(student &a, student &b)// 平均分排名 { return a.C > b.C; } bool Cmp3(student &a, student &b)// 平均分排名 { return a.M > b.M; } bool Cmp4(student &a, student &b)// 平均分排名 { return a.E > b.E; } int main() { int N, Mm; cin >> N >> Mm; map<string, int> mp; vector<student> v(N); string id; int C, M, E; double avg; for (int i = 0; i < N; i++) { cin >> v[i].name; cin >> v[i].C >> v[i].M >> v[i].E; v[i].Avg(); } sort(v.begin(), v.end(), Cmp1); v[0].rank[0] = 1; for (int i = 1; i < N; i++) { if (v[i].A == v[i - 1].A) { v[i].rank[0] = v[i - 1].rank[0]; } else { v[i].rank[0] = i + 1; } } sort(v.begin(), v.end(), Cmp2); v[0].rank[1] = 1; for (int i = 1; i < N; i++) { if (v[i].C == v[i - 1].C) { v[i].rank[1] = v[i - 1].rank[1]; } else { v[i].rank[1] = i + 1; } } sort(v.begin(), v.end(), Cmp3); v[0].rank[2] = 1; for (int i = 1; i < N; i++) { if (v[i].M == v[i - 1].M) { v[i].rank[2] = v[i - 1].rank[2]; } else { v[i].rank[2] = i + 1; } } sort(v.begin(), v.end(), Cmp4); v[0].rank[3] = 1; for (int i = 1; i < N; i++) { if (v[i].E == v[i - 1].E) { v[i].rank[3] = v[i - 1].rank[3]; } else { v[i].rank[3] = i + 1; } } for (int i = 0; i < N; i++) { mp[v[i].name] = i; if (i == 0) mp[v[i].name] = -1; } for (int i = 0; i < Mm; i++) { cin >> id; if (mp[id] != 0) { if (mp[id] == -1) v[0].BestRank(); else v[mp[id]].BestRank(); } else cout << "N/A" << endl; } system("pause"); }
老老实实的笨办法
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const char symbol[4] = { 'A', 'C', 'M', 'E' };
struct stu
{
string ID;
int A, C, M, E;
vector<int> rank;
stu() {
this->rank.resize(4);
}
bool operator == (const string &i) {
return this->ID == i;
}
};
vector<stu> stus;
vector<string> query_ids;
bool Comp1(const stu &a, const stu &b)
{
return a.A > b.A;
}
bool Comp2(const stu &a, const stu &b)
{
return a.C > b.C;
}
bool Comp3(const stu &a, const stu &b)
{
return a.M > b.M;
}
bool Comp4(const stu &a, const stu &b)
{
return a.E > b.E;
}
int main()
{
int M, N;
cin >> M >> N;
for (int i = 0; i < M; i++) {
stu temp;
cin >> temp.ID;
cin >> temp.C;
cin >> temp.M;
cin >> temp.E;
temp.A = (temp.C + temp.M + temp.E) / 3;
stus.push_back(temp);
}
query_ids.resize(N);
for (int i = 0; i < N; i++)
cin >> query_ids[i];
sort(stus.begin(), stus.end(), Comp1);
int count = 1;
stus[0].rank[0] = 1;
for (int i = 1; i < stus.size(); i++) {
if (stus[i].A == stus[i - 1].A) {
stus[i].rank[0] = stus[i - 1].rank[0];
count++;
}
else {
stus[i].rank[0] = stus[i - 1].rank[0] + count;
count = 1;
}
}
sort(stus.begin(), stus.end(), Comp2);
count = 1;
stus[0].rank[1] = 1;
for (int i = 1; i < stus.size(); i++) {
if (stus[i].C == stus[i - 1].C) {
stus[i].rank[1] = stus[i - 1].rank[1];
count++;
}
else {
stus[i].rank[1] = stus[i - 1].rank[1] + count;
count = 1;
}
}
sort(stus.begin(), stus.end(), Comp3);
count = 1;
stus[0].rank[2] = 1;
for (int i = 1; i < stus.size(); i++) {
if (stus[i].M == stus[i - 1].M) {
stus[i].rank[2] = stus[i - 1].rank[2];
count++;
}
else {
stus[i].rank[2] = stus[i - 1].rank[2] + count;
count = 1;
}
}
sort(stus.begin(), stus.end(), Comp4);
count = 1;
stus[0].rank[3] = 1;
for (int i = 1; i < stus.size(); i++) {
if (stus[i].E == stus[i - 1].E) {
stus[i].rank[3] = stus[i - 1].rank[3];
count++;
}
else {
stus[i].rank[3] = stus[i - 1].rank[3] + count;
count = 1;
}
}
vector<stu>::iterator iter;
int min_pos;
for (int i = 0; i < query_ids.size(); i++) {
if ((iter=find(stus.begin(), stus.end(), query_ids[i])) == stus.end()) {
cout << "N/A" << endl;
}
else {
min_pos = min_element(stus[iter - stus.begin()].rank.begin(),
stus[iter - stus.begin()].rank.end()) - stus[iter - stus.begin()].rank.begin();
cout << stus[iter - stus.begin()].rank[min_pos] << " " << symbol[min_pos] << endl;
}
}
return 0;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class TheBestRank {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int N=reader.nextInt();
int M=reader.nextInt();
HashMap info=new HashMap();
ArrayList agrade=new ArrayList();
ArrayList cgrade=new ArrayList();
ArrayList mgrade=new ArrayList();
ArrayList egrade=new ArrayList();
int[] score;
String id;
int c,m,e,a;
for(int i=0;i<N;i++){
score=new int[4];
id=reader.next();
c=reader.nextInt();
m=reader.nextInt();
e=reader.nextInt();
a=(c+m+e)/3;
agrade.add(a);
cgrade.add(c);
mgrade.add(m);
egrade.add(e);
score[0]=a;
score[1]=c;
score[2]=m;
score[3]=e;
info.put(id, score);
}
Collections.sort(agrade);
Collections.sort(cgrade);
Collections.sort(mgrade);
Collections.sort(egrade);
a=0;
c=0;
m=0;
e=0;
for(int i=0;i<M;i++){
id=reader.next();
if(!info.containsKey(id)){
System.out.println("N/A");
}else{
score=info.get(id);
for(int j=0;j<N;j++){
if(score[0]>=agrade.get(j)){
a=j;
}
if(score[1]>=cgrade.get(j)){
c=j;
}
if(score[2]>=mgrade.get(j)){
m=j;
}
if(score[3]>=egrade.get(j)){
e=j;
}
}
if(a>=c&&a>=m&&a>=e){
System.out.println(N-a+" A");
}else if(c>=m&&c>=e){
System.out.println(N-c+" C");
}else if(m>=e){
System.out.println(N-m+" M");
}else {
System.out.println(N-e+" E");
}
}
}
reader.close();
}
}