Result: Accepted
Time: 10ms
Memory: 1092kB
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct fun{
char name[101];
int fen;
};
int main()
{
struct fun x[1000],w;
int a,t,b,c,d,e,g,h;
char y[100];
scanf("%d",&a);
for(b=0;b<a;b++)
scanf("%s %d",x[b].name,&x[b].fen);
for(b=0;b<a-1;b++)
{
for(c=b;c<a;c++)
{
if(x[b].fen<x[c].fen)
{
w=x[b];
x[b]=x[c];
x[c]=w;
}
}
}
scanf("%d",&c);
while(c--)
{
scanf("%s",y);
d=strlen(y);
for(e=0;e<a;e++)
{
g=0;
for(b=0;b<d;b++)
{
if(y[b]==x[e].name[b])
g++;
}
if(g==d)
{
h=0;
for(b=0;b<e;b++)
if(x[e].fen<x[b].fen)
h++;
printf("%d\n",h);
break;
}
}
}
}