Start: Dec, 27, 2015 17:15:00
2015年秋学期《程序设计基础》第三次上机考试
End: Dec, 27, 2015 20:45:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 3ms
Memory: 1392kB
Author: 2015210402036
In contest: 1043

#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;
}