PAT甲级 1012 The Best Rank

需要注意的问题是并列第二都是第二名,所以单纯的排序时,并列第二所在位置是第二和第三,所以还需要处理。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
char bestone[2005];
int best[2005];
typedef struct student
{
    int id;
    int c;
    int m;
    int e;
    int a;

    int best=INF;
    char bestone;    
}stu;
stu a[2005];

int n, m;

bool cmp0(stu a,stu b)
{
    return a.e>b.e;
}
bool cmp1(stu a,stu b)
{
    return a.m>b.m;
}
bool cmp2(stu a,stu b)
{
    return a.c>b.c;
}
bool cmp3(stu a,stu b)
{
    return a.a>b.a;
}

void review(char c)
{
    for(int i = 0;i<n;i++)
        best[i] = i;
    for(int i = 0;i<n;i++)
    {
        if (i != 0)
        {
            if (c == 'E')
            {
                if (a[i].e == a[i - 1].e)
                    best[i] = best[i - 1];
            }
            else if (c == 'M')
            {
                if (a[i].m == a[i - 1].m)
                    best[i] = best[i - 1];
            }
            else if (c == 'C')
            {
                if (a[i].c == a[i - 1].c)
                    best[i] = best[i - 1];
            }
            else if (c == 'A')
            {
                if (a[i].a == a[i - 1].a)
                    best[i] = best[i - 1];
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (best[i] <= a[i].best)
        {
            a[i].best = best[i];
            a[i].bestone = c;
        }
        
        
    }
}

int main()
{
    memset(best,INF,sizeof(best));
    scanf("%d %d",&n,&m);
    for(int i = 0;i<n;i++)
    {
        scanf("%d %d %d %d",&a[i].id,&a[i].c,&a[i].m,&a[i].e);
        a[i].a = (a[i].c+a[i].m+a[i].e)/3;
    }
    sort(a,a+n,cmp0);
    review('E');
    sort(a,a+n,cmp1);
    review('M');
    sort(a,a+n,cmp2);
    review('C');
    sort(a,a+n,cmp3);
    review('A');
    for(int i = 0;i<m;i++)
    {
        int temp;
        int flag = 0;
        scanf("%d",&temp);
        for(int j = 0;j<n;j++)
        {
            if(temp == a[j].id)
            {
                printf("%d %c\n",a[j].best+1,a[j].bestone);
                flag  = 1;
            }
        }
        if(flag == 0)printf("N/A\n");

    }
    return 0;

    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值