codeforces 2-A Winner

本文介绍了一个使用C++解决的编程竞赛题目,主要通过结构体数组和字符串比较来实现字典功能,用于记录参赛者的得分情况,并找出最高分获得者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不会c++的STL的MAP,一看到这类字典题,我就感觉无底。题意思坑了我一回又一回。我本以为刚好第一个正好达到最后最大分才是WINNER,没想到曾超过后来才减到的也算。

#include<cstdio>
#include<cstring>

struct STU
{
    int sco;
    char name[33];
}stu[1010] ;
int tmp[1010];
int nexttmp[1010];
int link[1010];

int main()
{
    int n, i, j, k, maxsco;
    char str[33];
    while(~scanf("%d", &n))
    {
    int top = 0;
    for(i = 0; i < n; i++)
    {
        scanf("%s%d",str, &tmp[i]);
        for(j = 0; j < top; j++)
        {
            if(strcmp(stu[j].name, str) == 0)
            {
                stu[j].sco += tmp[i];
                link[i] = j;
                break;
            }
        }
        if(j >= top)
        {
            strcpy(stu[top].name, str);
            stu[top].sco = tmp[i];
            link[i] = top;
            top ++;
        }
    }
    maxsco = -1;
    for(i = 0; i < top; i++)
        if(maxsco < stu[i].sco)maxsco = stu[i].sco;
    memset(nexttmp, 0, sizeof(nexttmp));
    for(i = 0; i < n; i++)
    {
        if(stu[link[i]].sco == maxsco)
        {
        nexttmp[link[i]] += tmp[i];
        if(nexttmp[link[i]] >= maxsco)
        {
            printf("%s\n", stu[link[i]].name);
            break;
        }
        }
    }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值