#include<stdio.h>#include<algorithm>Usingnamespace Std;struct student{int MID;int grade[4];0 corresponds to the average a,1 corresponding to the c,2 corresponding to the m,3 corresponding e}stu[2010];Char course[4]={' A ',' C ',' M ',' E '};All storage corresponds to Acmeint rank[10000000][4]={0};Ranking of four grades per study numberint now=0;When sorting, press now for this class.BOOL CMP (Student a,student b) {Return a.grade[now]>b.grade[now];Sort by the first grade of "warning" here to order by now scores from large to small, write "<" do not write ">"}int main () {int n,m; scanf"%d%d", &n,&m);n Inputs, M queriesForint i=0; I<n; ++i) {scanf ("%d%d%d%d", &stu[i].mid, &stu[i].grade[1], &stu[i].grade[2], &stu[i].grade[3]); stu[i].grade[0]= (stu[i].grade[1]+stu[i].grade[2]+stu[i].grade[3])/3; }for (now=0; now<4; ++now)For each course, sort by now and record the rank in rank {sort (stu,stu+n,cmp); rank[stu[0].mid][now]=1;Post-order structure first first in the now standardForint i=1; I<n; ++i)if (stu[i].grade[now]==stu[i-1].grade[now])Scores are the same, and rank "thinking": the same as the previous one, different i+1 rank[stu[i].mid][now]=rank[stu[i-1].mid][now];else rank[stu[i].mid][now]=i+1; }int query;Forint i=0; I<m; ++i) {scanf ("%d", &query);if (rank[query][0]==0) / /rank must be a ..., when it comes up, this school number must have a problem printf ( "n/a< Span class= "char" >\nelse {int k=0; for (int j=0; j< 4; ++j) if (rank[query][j]<rank[query][k]) //enumeration of the number of all subjects ranked, the most pre-test saved in the K k=j; printf ( "%d%c\nreturn 0;}
pat:1012. The best Rank (+) AC