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: 2ms
Memory: 1192kB
Author: 719034075
In contest: 1043

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct student{
char name[102];
int grade;
int no;
};
typedef struct student a;
int comp(const void*p,const void*q){
return ((struct student*)q)->grade-((struct student*)p)->grade;
}
int main(){
a s[1001];
int n,m,i,j,len;
char b[1001][102];
int c[1001];
while(scanf("%d",&n)!=EOF){
	for(i=0;i<n;i++){
		scanf("%s %d",s[i].name,&s[i].grade);
		getchar();
	}
	qsort(s,n,sizeof(s[0]),comp);
	s[0].no=0;
	for(i=1;i<n;i++){
		if(s[i].grade==s[i-1].grade)
			s[i].no=s[i-1].no;
		else
			s[i].no=i;
	}

	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%s",b[i]);
		len=strlen(b[i]);
		b[i][len]=':';
		b[i][len+1]='\0';
	for(j=0;j<n;j++)
		if(strcmp(b[i],s[j].name)==0)
			c[i]=s[j].no-s[0].no;
	}
	for(i=0;i<m;i++)
		printf("%d\n",c[i]);
}
return 0;
}