栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

PAT甲级 - 1012 The Best Rank(坑点)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PAT甲级 - 1012 The Best Rank(坑点)

Link

题意:大概题意就是每个学生都有自己的序号id,以及C语言场景c,数学成绩m,英语成绩e,以及平均成绩a。题目会输出n个学生的id以及三门主科的成绩,气候跟寻m次询问,问某id的学生最佳成绩排名及科目名称。

思路:思路其实很简单,分四个数组存放每科所有学生的成绩再排个序即可。但需要注意两个坑点:1.在选取学生最高排名时必须按照a,c,m,e的优先级取最高排名科目(即每个成绩都排名第三,但必须输出 3 A)。2. 相同分数排名相同,但下一分数不会递补(即现在有 90、90、89的三个成绩,则气排名分别为1、1、3)。

AC代码:

#include
#define int long long
#define endl 'n'
using namespace std;
const int N = 1e5+10;

int n, m;
struct node{
    int c, m, e, a;
};

map mp;
vector cc, mm, ee, aa;
map gc, gm, ge, ga;
map vis;

bool cmpc(node x, node y){
    return x.c>y.c;
}
bool cmpm(node x, node y){
    return x.m>y.m;
}
bool cmpe(node x, node y){
    return x.e>y.e;
}
bool cmpa(node x, node y){
    return x.a>y.a;
}

signed main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        string s; int x, y, z;
        cin >> s >> x >> y >> z;
        vis[s] = 1;
        node tmp = {x, y, z, (x+y+z)/3};
        mp[s] = tmp;
        cc.push_back(tmp);
        mm.push_back(tmp);
        ee.push_back(tmp);
        aa.push_back(tmp);
    }

    sort(cc.begin(), cc.end(), cmpc);
    sort(mm.begin(), mm.end(), cmpm);
    sort(ee.begin(), ee.end(), cmpe);
    sort(aa.begin(), aa.end(), cmpa);

    for(int i = 0; i < cc.size(); i ++){
        if(!gc[cc[i].c]) gc[cc[i].c] = i+1;
    }
    for(int i = 0; i < mm.size(); i ++){
        if(!gm[mm[i].m]) gm[mm[i].m] = i+1;
    }
    for(int i = 0; i < ee.size(); i ++){
        if(!ge[ee[i].e]) ge[ee[i].e] = i+1;
    }
    for(int i = 0; i < aa.size(); i ++){
        if(!ga[aa[i].a]) ga[aa[i].a] = i+1;
    }

    while(m--){
        string s;
        cin >> s;
        if(!vis[s]){
            cout << "N/A" << endl;
            continue;
        }
        int pc = gc[mp[s].c], pm = gm[mp[s].m], pe = ge[mp[s].e], pa = ga[mp[s].a];
        if(pa<=pc&&pa<=pm&&pa<=pe) cout << pa << " A" << endl;
        else if(pc<=pm&&pc<=pe&&pc<=pa) cout << pc << " C" << endl;
        else if(pm<=pc&&pm<=pe&&pm<=pa) cout << pm << " M" << endl;
        else if(pe<=pc&&pe<=pm&&pe<=pa) cout << pe << " E" << endl;
//        cout << mp[s].c << " " << mp[s].m << " " << mp[s].e << " " << mp[s].a << endl;
//        cout << pc << " " << pm << " " << pe << " " << pa << endl << endl;
    }

    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/928891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号