Result: Accepted
Time: 22ms
Memory: 1816kB
#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;
}
}
}
}