Result: Accepted
Time: 3ms
Memory: 1392kB
#include <stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
struct node
{
int score;
int num;
char name[200];
};
int comp(const void *p, const void *q)
{
return ((struct node *)q)->score - ((struct node *)p)->score;
}
int main()
{
int n, i, j, m, cnt;
char tmp[200];
while(~scanf("%d", &n))
{
struct node list[2001];
for(i = 0 ; i < n; i++)
{
scanf("%s %d", list[i].name, &list[i].score);
getchar();
cnt = 0;
while(list[i].name[cnt] != ':')
{
cnt++;
}
list[i].name[cnt] = '\0';
}
qsort(list, n, sizeof(list[0]), comp);
for(i = 0; i < n; i++)
{
if(i > 0 && list[i].score == list[i - 1].score)
list[i].num = list[i - 1].num;
else
{
if(i == 0)
list[i].num = 1;
else
list[i].num = i + 1;
}
}
scanf("%d", &m);
getchar();
for(j = 0; j < m; j++)
{
scanf("%s", tmp);
getchar();
for(i = 0; i < n; i ++)
{
if(strcmp(list[i].name, tmp) == 0)
{
printf("%d\n", list[i].num - 1);
break;
}
}
}
}
return 0;
}