Result: Accepted
Time: 46ms
Memory: 1276kB
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct f{
char a[100],c[100];
int x;
};
int comp(const void *p,const void *q){
return ((struct f *)q)->x-((struct f *)p)->x;
}
void main()
{
struct f b[1001];
int i,j,k,h,n,m,z;
char c[1000][100];
scanf("%d",&n);
for(i=0;i<n;++i)
scanf("%s %d",&b[i].a,&b[i].x);
qsort(b,n,sizeof(struct f),comp);
scanf("%d",&m);
for(j=0;j<m;++j)
{
scanf("%s",&c[j]);
for(h=0;h<n;++h)
{
z=0;
for(k=0;k<strlen(c[j]);++k)
{
if(c[j][k]==b[h].a[k])
z++;
}
if(z==strlen(c[j]))
{
for(i=0;i<n;++i)
{
if(b[h].x==b[i].x)
{
printf("%d\n",i);
break;
}
}
}
}
}
}