1012 The Best Rank (25分)

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn = 2020;

typedef struct record
{
    int id;
    int grade[4];
};

int n,m,now=0; //now全部变量利于循环在cmp函数中比较
record stu[Maxn];
int ranklist[1000000][4] = {0}; //设置数组来记录排名
char sub[4] = {'A','C','M','E'}; //用数字来对应科目
bool cmp(record a,record b)
{
    return a.grade[now] > b.grade[now];
}


int main()
{
    freopen("1.txt","r",stdin);
    scanf("%d %d",&n,&m);
    for(int i = 0;i<n;i++)
    {
        cin>>stu[i].id>>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]; //总值代替平均
    }

    for(now = 0;now<4;now++)
    {
        sort(stu,stu+n,cmp); //对当前科目排名
        ranklist[stu[0].id][now] = 1;
        for(int i = 1;i<n;i++)
        {
            if(stu[i].grade[now] == stu[i-1].grade[now])
                ranklist[ stu[i].id ][now] = ranklist[ stu[i-1].id ][now]; //记录排名
            else
                ranklist[ stu[i].id ][now] = i + 1;
        }
    }
    int temp;
    for(int i = 0;i<m;i++)
    {
        
        scanf("%d",&temp);
        if(ranklist[temp][0] == 0) //为0即没有该记录
        {
            printf("N/A\n");
            //break;  //break掉后面的记录都不能查询了!!!
        }
        else
        {
             int top = 5,f = 0;
            for(int j = 0;j<4;j++) //第一个寻找到就是优先度最高的
            {
                if(top > ranklist[temp][j])
                {
                    top = ranklist[temp][j];
                    f = j;
                }
            }
            printf("%d %c\n",top,sub[f]);
        }


    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值