
Rankings Search
https://codeforces.com/group/cRJbcAFEwS/contest/485694/problem/D
Question
Abby and Cody want to make a new website called Abakoda, where beginner programmers can join friendly programming contests and improve their skills.
Now they are working on displaying the contest rankings. They want to make a search bar, where a contestant can type their name in, and the rankings will automatically focus on their position in the rankings.
Abby and Cody need your help. In Rankings Order, you figured out together how to display the contestants in order. Now, write a program that processes several requests from contestants to find their position in the rankings.
Input Format
The input contains several lines.
The first line of input contains one integer n, the number of contestants.
This is followed by n lines of input. These lines describe the rankings. These lines will be arranged according to the order described in Rankings Order. Each of these lines contains a name and a score, separated by a space, representing the name and score of a single contestant. The name contains only lowercase English letters, no spaces, and no punctuation marks. Each name contains at least one letter. The score is one of the following: , , , , or .
This is followed by a line containing an integer s, the number of search requests.
This is followed by s lines of input. Each of these lines contains a name containing only lowercase English letters, no spaces, and no punctuation marks. These names are all names of contestants, which have appeared previously in the part of the input describing the rankings.
Constraints
No two contestants have the same name.
The length of each name does not exceed 10.
Output Format
Your program must print lines of output. Each line must contain a single integer. The -th line of the output must contain the answer to the -th search request in the input: the position of a contestant in the rankings. The topmost position in the rankings is position .
Sample Inputs:
Input
4
abby 400
cody 300
aba 200
koda 100
5
aba
abby
koda
cody
koda
Output
3
1
4
2
4
Explanation:
In the sample test case, there are four contestants, displayed in order.
Contestant abby has 400 points.
Contestant cody has 300 points.
Contestant aba has 200 points.
Contestant koda has 100 points.
There are five requests:
A request to find contestant aba, who is at position .
A request to find contestant abby, who is at position .
A request to find contestant koda, who is at position .
A request to find contestant cody, who is at position .
A request to find contestant koda, who is at position .
Notice that some requests may be duplicated (when a contestant searches their name more than once).
Last updated