PAT (Advanced Level) Practice - 1012 The Best Rank(25 分)

简介: PAT (Advanced Level) Practice - 1012 The Best Rank(25 分)

题目链接:点击打开链接

题目大意:取要查询的学号的最优排名:指的是优先名次最高的选择,但若有多个名次一样的,则按 A > C > M > E 优先级来。若学号不存在,输出 “N/A”。

解题思路:略。

AC 代码

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct RK
{
    char c;
    int rk;
};
struct node
{
    string id;
    int c,m,e,a;
}nds[3000];
struct peo
{
    RK rks[4];
};
unordered_map<string,peo> ump;
int cmp_c(node n1,node n2)
{
    return n1.c>n2.c;
}
int cmp_m(node n1,node n2)
{
    return n1.m>n2.m;
}
int cmp_e(node n1,node n2)
{
    return n1.e>n2.e;
}
int cmp_a(node n1,node n2)
{
    return n1.a>n2.a;
}
int cmp(RK r1,RK r2)
{
    if(r1.rk==r2.rk) return r1.c<r2.c;
    return r1.rk<r2.rk;
}
int main()
{
    int n,k,c,a,m,e;
    char id[10];
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%s%d%d%d",id,&c,&m,&e);
            nds[i].id=id;
            nds[i].c=c;
            nds[i].m=m;
            nds[i].e=e;
            nds[i].a=int((c+m+e)*1.0/3+0.5);
        }
        ump.clear();
        sort(nds,nds+n,cmp_c);
        node nd=nds[0];
        int rk=1;
        ump[nd.id].rks[0].rk=rk;
        ump[nd.id].rks[0].c='C';
        for(int i=1;i<n;i++)
        {
            nd=nds[i];
            if(nd.c==nds[i-1].c)
                ump[nd.id].rks[0].rk=rk, ump[nd.id].rks[0].c='C';
            else
                ump[nd.id].rks[0].rk=i+1, ump[nd.id].rks[0].c='C', rk=i+1;
        }
        sort(nds,nds+n,cmp_m);
        nd=nds[0];
        rk=1;
        ump[nd.id].rks[1].rk=rk;
        ump[nd.id].rks[1].c='M';
        for(int i=1;i<n;i++)
        {
            nd=nds[i];
            if(nd.m==nds[i-1].m)
                ump[nd.id].rks[1].rk=rk, ump[nd.id].rks[1].c='M';
            else
                ump[nd.id].rks[1].rk=i+1, ump[nd.id].rks[1].c='M', rk=i+1;
        }
        sort(nds,nds+n,cmp_e);
        nd=nds[0];
        rk=1;
        ump[nd.id].rks[2].rk=rk;
        ump[nd.id].rks[2].c='Z';
        for(int i=1;i<n;i++)
        {
            nd=nds[i];
            if(nd.e==nds[i-1].e)
                ump[nd.id].rks[2].rk=rk, ump[nd.id].rks[2].c='Z';
            else
                ump[nd.id].rks[2].rk=i+1, ump[nd.id].rks[2].c='Z', rk=i+1;
        }
        sort(nds,nds+n,cmp_a);
        nd=nds[0];
        rk=1;
        ump[nd.id].rks[3].rk=rk;
        ump[nd.id].rks[3].c='A';
        for(int i=1;i<n;i++)
        {
            nd=nds[i];
            if(nd.a==nds[i-1].a)
                ump[nd.id].rks[3].rk=rk, ump[nd.id].rks[3].c='A';
            else
                ump[nd.id].rks[3].rk=i+1, ump[nd.id].rks[3].c='A', rk=i+1;
        }
        for(unordered_map<string,peo>::iterator it=ump.begin(); it!=ump.end(); it++)
            sort(it->second.rks,it->second.rks+4,cmp);
        for(int i=0;i<k;i++)
        {
            scanf("%s",id);
            if(ump[id].rks[0].rk==0) puts("N/A");
            else printf("%d %c\n",ump[id].rks[0].rk,ump[id].rks[0].c=='Z'?'E':ump[id].rks[0].c);
        }
    }
    return 0;
}
目录
相关文章
PAT (Advanced Level) Practice - 1146 Topological Order(25 分)
PAT (Advanced Level) Practice - 1146 Topological Order(25 分)
86 0
PAT (Advanced Level) Practice - 1122 Hamiltonian Cycle(25 分)
PAT (Advanced Level) Practice - 1122 Hamiltonian Cycle(25 分)
117 0
|
测试技术
PAT (Advanced Level) Practice - 1029 Median(25 分)
PAT (Advanced Level) Practice - 1029 Median(25 分)
116 0
PAT (Advanced Level) Practice - 1095 Cars on Campus(30 分)
PAT (Advanced Level) Practice - 1095 Cars on Campus(30 分)
130 0
PAT (Advanced Level) Practice - 1147 Heaps(30 分)
PAT (Advanced Level) Practice - 1147 Heaps(30 分)
119 0
PAT (Advanced Level) Practice - 1103 Integer Factorization(30 分)
PAT (Advanced Level) Practice - 1103 Integer Factorization(30 分)
99 0
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
111 0
PAT (Advanced Level) Practice - 1062 Talent and Virtue(25 分)
PAT (Advanced Level) Practice - 1062 Talent and Virtue(25 分)
140 0
PAT (Advanced Level) Practice - 1118 Birds in Forest(25 分)
PAT (Advanced Level) Practice - 1118 Birds in Forest(25 分)
109 0
|
存储
PAT (Advanced Level) Practice - 1126 Eulerian Path(25 分)
PAT (Advanced Level) Practice - 1126 Eulerian Path(25 分)
138 0