7. F1方程式冠军

【问题描述】

一级方程式F1锦标赛由一系列称为大奖赛的分站赛组成。每一场比赛的车手都根据他们的最后位置获得积分。只有前10名车手按以下顺序获得分数:25、18、15、12、10、8、6、4、2、1。在锦标赛结束时,得分最多的车手是冠军。如果有平分,则冠军是赢的最多的人(即排位第一)。如果还是平分,则选择得到排位第二最多的人,依此类推,直到没有更多的排位进行比较。

后来又提出了另一个得分制度,其中冠军是赢的最多的。如果有平手,冠军是得分最多的。如果仍然存在平手,则按原来的得分制度进行,即比较第二、第三、第四、…排位的次数。

在本赛季,你会得到所有比赛的结果,你将根据两个得分系统来分别确定冠军。数据保证两套系统都能得到唯一的冠军。

【输入形式】

第一行一个整数t(1<=t<=20),t是分站赛的场次数。之后是每个分站赛的最终排位情况,每个的第一行一个整数n(1<=n<=100)表示排位车手人数,之后n行按排位列出车手的名字,排位从第一到最后,车手的名字为长度不超过50的英文字符,大小写区分。

#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct competitor
{ //每位参赛者
    int score = 0;
    unsigned short maps[101]; //因为最多一百人排名,名次数最多到一百, 从一开始
    string name;
};
bool cmp1(competitor a, competitor b)
{
    if (a.score != b.score)
        return a.score > b.score;
    else
        for (int i = 1; i <= 100; i++) //从第一排位的次数比起
            if (a.maps[i] != b.maps[i])
                return a.maps[i] > b.maps[i];
}
bool cmp2(competitor a, competitor b)
{
    if (a.maps[1] != b.maps[1])
        return a.maps[1] > b.maps[1];
    else if (a.score != b.score)
        return a.score > b.score;
    else
        for (int i = 2; i <= 100; i++) //从第二排位的次数比起
            if (a.maps[i] != b.maps[i])
                return a.maps[i] > b.maps[i];
}
int main()
{
    int n, tag = 0, tmp;
    string name;
    competitor compe[100];           //最多一百位参赛者
    unordered_map<string, int> maps; //名字与数组下标的映射
    unordered_map<int, int> score{
        {1, 25},
        {2, 18},
        {3, 15},
        {4, 12},
        {5, 10},
        {6, 8},
        {7, 6},
        {8, 4},
        {9, 2},
        {10, 1}}; //名次与分数的映射
    //输入处理
    cin >> n;
    for (int i = 0; i < n; i++)
    { //有几个分站比赛
        int m;
        cin >> m;
        for (int j = 1; j <= m; j++)
        { //有几个人参与排名, j是名次
            cin >> name;
            if (maps.find(name) == maps.end())
            { //新出现的名字
                compe[tag].name = name;
                maps[name] = tag++;
            }
            tmp = maps[name];     //暂存下标
            compe[tmp].maps[j]++; //排名j次数加一
            if (j <= 10)          //排名小于十才加分
                compe[tmp].score += score[j];
        }
    }

    //统计完成, 开始用两种方法计算第一名
    //第一种
    sort(compe, compe + tag, cmp1);
    cout << compe[0].name << endl;

    //第二种
    sort(compe, compe + tag, cmp2);
    cout << compe[0].name << endl;

    return 0;
}
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值