#7出错,讨论区的例子试过了没有问题
  • 板块CF2A Winner
  • 楼主lzjhandsome
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/4/20 20:15
  • 上次更新2023/10/28 03:14:20
查看原帖
#7出错,讨论区的例子试过了没有问题
547491
lzjhandsome楼主2022/4/20 20:15
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int input[1000][1000][2]={0};
int foundIndex(char s[1000][40],char *temp,int * cnt)
{

    for(int i=0;i<*cnt;i++)
    {
        if (!strcmp(temp,s[i]))
        return i;
    }
    strcpy(s[(*cnt)++],temp);
    return *cnt-1;
}
int main()
{
    int n,score[1000]={0},cnt=0,t,pos,maxvalue=-90,maxnum=0,posi[1000]={0},max[1000],mini=1001,min,j;
    char s[1000][40],temp[40];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s %d",temp,&t);
        pos=foundIndex(s,temp,&cnt);//find the index of name ,if not create a new position
        score[pos]+=t;
        input[pos][posi[pos]++][0]=score[pos];//the input Array stored the every round score where the score changed
        input[pos][posi[pos]-1][1]=i+1;
    }
    for(int i=0;i<cnt;i++)
    {
        if(score[i]>maxvalue)//
        {
            maxnum=1;
            max[maxnum-1]=i;
            maxvalue=score[i];
        }
        else if(score[i]==maxvalue)
        {
            maxnum++;
            max[maxnum-1]=i;
        }
    }
    for(int i=0;i<maxnum;i++)
    {
        for(j=0;j<posi[max[i]];j++)
        {
            if(input[i][j][0]>=maxvalue)
            break;
        }
        if(input[i][j][1]<mini)
        {
            mini=input[i][j][1];
            min=max[i];
        }
    }
    printf("%s",s[min]);
}
2022/4/20 20:15
加载中...