标签:lse i++ col include char click string 注意 har
注意一下相同分数的排名相同,比如98,97,97,96的排名是1,2,2,4
#include <bits/stdc++.h> using namespace std; #define maxn 100005 struct Student { string name; int c,m,e,ra,rc,rm,re; double avg; }stu[maxn]; char c[]={‘A‘,‘C‘,‘M‘,‘E‘}; bool acmp(Student a,Student b) { return a.avg>b.avg; } bool ccmp(Student a,Student b) { return a.c>b.c; } bool mcmp(Student a,Student b) { return a.m>b.m; } bool ecmp(Student a,Student b) { return a.e>b.e; } map<string,int> vis,ma,mb; int n,m; int main() { vis.clear(); cin>>n>>m; for(int i=0;i<n;i++) { cin>>stu[i].name>>stu[i].c>>stu[i].m>>stu[i].e; stu[i].avg=(double)(stu[i].c+stu[i].m+stu[i].e)/3.0; vis[stu[i].name]=1; } sort(stu,stu+n,acmp); int p=1; stu[0].ra=1; for(int i=1;i<n;i++) { if(stu[i].avg==stu[i-1].avg) stu[i].ra=p; else { p=i+1; stu[i].ra=p; } } sort(stu,stu+n,ccmp); p=1; stu[0].rc=1; for(int i=1;i<n;i++) { if(stu[i].c==stu[i-1].c) stu[i].rc=p; else { p=i+1; stu[i].rc=p; } } sort(stu,stu+n,mcmp); p=1; stu[0].rm=1; for(int i=1;i<n;i++) { if(stu[i].m==stu[i-1].m) stu[i].rm=p; else { p=i+1; stu[i].rm=p; } } sort(stu,stu+n,ecmp); p=1; stu[0].re=1; for(int i=1;i<n;i++) { if(stu[i].e==stu[i-1].e) stu[i].re=p; else { p=i+1; stu[i].re=p; } } int minn,crs,ans; for(int i=0;i<n;i++) { minn=n+1; if(stu[i].ra<minn) { ans=stu[i].ra; minn=stu[i].ra; crs=0; } if(stu[i].rc<minn) { ans=stu[i].rc; minn=stu[i].rc; crs=1; } if(stu[i].rm<minn) { ans=stu[i].rm; minn=stu[i].rm; crs=2; } if(stu[i].re<minn) { ans=stu[i].re; minn=stu[i].re; crs=3; } ma[stu[i].name]=ans; mb[stu[i].name]=crs; } string s; while(m--) { cin>>s; if(vis[s]==1) cout<<ma[s]<<" "<<c[mb[s]]<<endl; else cout<<"N/A"<<endl; } }
标签:lse i++ col include char click string 注意 har
原文地址:https://www.cnblogs.com/FTA-Macro/p/11440285.html