Note:Names consist of lowercase English alphabetic letters and arefirst namesonly.
TaskGivennames and phone numbers, assemble a phone book that maps friends names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For eachqueried, print the associated entry from your phone book on a new line in the formname=phoneNumber; if an entry foris not found, printNot foundinstead.
ByLAURENT*,November 4, 2017inGeneral and Gameplay Programming
phoneBook; //Number of names + phone numbers cin n; //Fill in Map and keys while (it n) cin name; cin number; sert(std::make_pair(name, number)).second != false) phoneBook.insert(std::make_pair(name, number)); it++; //Find the keys using the map for (int i = 0; i n; i++) cin name; if(phoneBook.find(name) != phoneBook.end()) coutname=phoneBook[name]endl; else if(phoneBook.find(name) == phoneBook.end()) coutNot foundendl; return 0;
Query 1:edwardEdward is not one of the keys in our dictionary, so we printNot found.
Query 0:samSam is one of the keys in our dictionary, so we printsam=99912222.
Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn moreAbout Usor sign up!
Copyright (c) 1999-2018 GameDev.net, LLCPowered by Invision Community
Already have an account? Sign in here.
After thelines of phone book entries, there arean unknown number of lines of queries. Each line (query) contains ato look up, and you must continue reading lines until there is no more input.
You need to be a member in order to leave a comment
The first line contains an integer,, denoting the number of entries in the phone book.Each of thesubsequent lines describes an entry in the form ofspace-separated values on a single line. The first value is a friends name, and the second value is an-digit phone number.
Sign up for a new account in our community. Its easy!
We add the following(Key,Value)pairs to our map so it looks like this:
using namespace std; int main() /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int it = 0; int n; int number; string name; std::map
Or sign in with one of these services
Note:Your phone book should be a Dictionary/Map/HashMap data structure.
By using GameDev.net, you agree to our communityGuidelinesTerms of Use, andPrivacy Policy.
Dont like ads? Consider ourGDNet+ Membershipsfor a no-ad experience.Yes, Ill Whitelist
Query 2:harryHarry is one of the keys in our dictionary, so we printharry=12299933.
We then process each query and printkey=valueif the queriedis found in the map; otherwise, we printNot found.
Test case 1 has over 100000 inputs. Here is the link they gave me. I didnt see a forum but they do seem to have some sort of discussion section. This is usually my go to place but that might stem from admiration, regardless I will be exploring hacker rank now.
We are the game development community.
ObjectiveToday, were learning about Key-Value pair mappings using aMaporDictionarydata structure. Check out theTutorialtab for learning materials and an instructional video!
On a new line for each query, printNot foundif the name has no corresponding entry in the phone book; otherwise, print the fullandin the formatname=phoneNumber.
I decided to take on competition and challenges across the internet. My place of choice at the moment is hacker rank. Im stuck on hacker ranks 30 day challenge day 8. I need to create a map key data structure for a phone book. The maps need to be the names of the people and the keys are their numbers. Does anyone know how to complete this challenge and could someone explain to me why test case 1 would fail with my code?
Does Hacker Rank have a forum where you could post this question? If not, you should probably link to the question and/or provide the actual test case (if their site terms allow you to do so, which Im not sure they do) so we can better assist you.