pat:1012. The best Rank AC

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.