Result: Accepted
Time: 23ms
Memory: 1172kB
#include<stdio.h>
#include<string.h>
int main()
{
int s[1000];
char s1[1000][100],
s2[1000][100];
int m,t,i,j,k,l,a,b,n,length;
scanf("%d",&n);
for (i=0;i<n;i++)
{ scanf("%s",&s1[i]);
scanf("%d",&s[i]); }
scanf("%d",&m);
for (i=0;i<m;i++)
{scanf("%s",s2[i]);}
a=0;b=0;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
{
length=strlen(s2[i]);
b=0;a=0;
for(k=0;k<length;k++)
{if (s2[i][k]!=s1[j][k]) b=1;}
if (b==0)
{
for (l=0;l<n;l++)
{
if (s[j]<s[l]) a=a+1;
}
printf("%d\n",a);
}
}
return 0;
}