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: 25ms
Memory: 12060kB
Author: NickJudy
In contest: 1043

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdio>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
struct h
{
	char a[1050];
	int b;
	int c;
}x[10000];
int cmp(h a,h b)
{
	return a.b>b.b;
}
int main(void)
{
	int n,l,l1,sum;
	cin>>n;
	for(int i=0;i<n;++i)
		cin>>x[i].a>>x[i].b;
	sort(x,x+n,cmp);
	x[0].c=1;
	for(int i=1;i<n;++i)
	{
		if(x[i].b==x[i-1].b)
			x[i].c=x[i-1].c;
		else x[i].c=i+1;
	}
	int t;
	cin>>t;
	getchar();
	while(t--)
	{
		char s[1050];
		cin>>s;
		l1=strlen(s);
		for(int i=0;i<n;++i)
		{
			sum=0;
			l=strlen(x[i].a);
			if(l1==l-1)
			{
			   for(int j=0;j<l1;++j)
			    {
					if(s[j]==x[i].a[j])
						sum++;
			    }
			   if(sum==l1)
			   {
				   cout<<x[i].c-1<<endl;
				   break;
			   }
			}
		}
	}
	return 0;
}