不会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;
}