• CodeForce 2A Winner


    很多人玩一个游戏,每一轮有一个人得分或者扣分,最后分数最高的人夺冠;如果最后有多个人分数都是最高的,则这些人里面,在比赛过程中首先达到或者超过这个分数的人夺冠。现在给定最多1000轮每轮的情况,求最后的冠军是谁。

    ========================================================================================

    #include <iostream>
    #include <cmath>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cstdlib>
    using namespace std;
    typedef long long LL;
    const LL INF = 0xffffff;
    const int maxn = 1005;
    const LL MOD = 1e9+7;
    struct node
    {
        char name[maxn];
        int coun;
        int sorce;
    } P[maxn], ans, Read[maxn];
    ///642
    
    int main()
    {
        int n, k = 0, i, j, Max = -INF;
        memset(P, 0, sizeof(P));
        ans.sorce = -INF;
        cin >> n;
    
        for(i=0; i<n; i++)
        {
            cin >> Read[i].name >> Read[i].sorce;
    
            for(j=0; j<k; j++)
            {
                if(strcmp(P[j].name, Read[i].name) == 0)
                {
                    P[j].sorce += Read[i].sorce;
                    break;
                }
            }
    
            if(j == k)
            {
                strcpy(P[j].name,Read[i].name);
                P[k++].sorce = Read[i].sorce;
            }
        }
    
        for(i=0; i<k; i++)
            Max = max(P[i].sorce, Max);
        k = 0;
        memset(P, 0, sizeof(P));
    
        for(i=0; i<n; i++)
        {
            for(j=0; j<k; j++)
            {
                if(strcmp(P[j].name, Read[i].name) == 0)
                {
                    P[j].sorce += Read[i].sorce;
                    if(P[j].sorce >= Max && P[j].coun == -1)
                        P[j].coun = i;
                    break;
                }
            }
    
            if(j == k)
            {
                strcpy(P[j].name,Read[i].name);
                P[k++].sorce = Read[i].sorce;
                P[j].coun = -1;
                if(P[j].sorce >= Max)
                    P[j].coun = i;
            }
        }
    
        for(i=0; i<k; i++)
        {
            if(ans.sorce < P[i].sorce || (ans.sorce == P[i].sorce && P[i].coun < ans.coun) )
                ans = P[i];
        }
    
        cout << ans.name << endl;
        return 0;
    }
  • 相关阅读:
    alpha冲刺9
    alpha冲刺8
    alpha冲刺7
    alpha冲6
    随堂小测-同学录
    alpha冲刺5
    任务3
    任务2
    任务1
    网站用户行为分析
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4839690.html
Copyright © 2020-2023  润新知