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: 22ms
Memory: 1816kB
Author: 2015210405001
In contest: 1043

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct st
{
	char s[105];
	int score;
}a[1005];
int cmp(struct st a,struct st b)
{
	return a.score>b.score;
}
int main()
{
	int n,m,i,b,j,r;
	char s[105];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i].s>>a[i].score;
		b=strlen(a[i].s)-1;
		a[i].s[b]='\0';
	}
	sort(a,a+n,cmp);
	cin>>m;
	while(m--)
	{
		cin>>s;
		for(i=0;i<n;i++)
		{
			if(!strcmp(s,a[i].s))
			{
				for(r=j=0;j<i;j++)
					if(a[j].score>a[i].score)
						r++;
				cout<<r<<endl;
			}
		}
	}
}