Search in Lex Fridman’s podcasts
Lex Fridman hosts a very interesting podcast where he calls different guests like Elon Musk, Joe Rogan, Andrej Karpathy, and Vitalik Buterin to name a few. Both you and your friend Anna really enjoy watching the podcasts. When discussing the podcasts, you like talking about the number of views the podcast got and who was the guest. You’ve decided to write that information out and keep it as a list of pairs
(guest, views). Now whenever Anna mentions a name of a guest, you can look at the list and find out the number of views that podcast got.
Can you write a program that would print the number of views for all the guests Anna was talking about?
The first line of the input contains a single integer
n(1 ≤ n ≤ 1000) - the number of podcasts you’ve kept as a list of pairs.
2nlines contain pairs of guests and views. First comes the name of the guest, then the number of views that the podcast obtained.
The following line contains a single integer
q(1 ≤ q ≤ n) - the number of questions Anna has about the podcast guests.
qlines are the names of the guests Anna talks about.
For each of the
qquestions, the program should print the number of views the podcast obtained.
5 Elon Musk 6400000 Joe Rogan 6200000 Kanye West 4000000 Vitalik Buterin 4500000 Mark Zuckerberg 3800000 3 Elon Musk Mark Zuckerberg Joe Rogan
6400000 3800000 6200000
Disclaimer: This method of searching for the right answer is called a linear search. We’ll learn how to perform faster queries for different types of problems in a bit.
Time limit: 1 seconds
Memory limit: 512 MB
Output limit: 1 MB