Saturday, 1 April 2017

Hacker Rank Solution For Day 8: Dictionaries and Maps

Problem:- Write a Hackerrank Solution For Day 8: Dictionaries and Maps or Hacker Rank Solution Program In C++ For " Day 8: Dictionaries and Maps " or Hackerrank 30 days of code Java Solution: Day 8: Dictionaries and Maps solution or Hackerrank solution for 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution: Day 8: Dictionaries and Maps, or C/C++ Logic & Problem Solving: Day 8: Dictionaries and Maps.


Hacker Rank Solution For Day 8: Dictionaries and Maps

Logic:- Day 8: Dictionaries and Maps as we know that Dictionaries is a collection of data(variety of data). So for this problem, we can take an example of the phone book. Phone book consists of various phone data line name, address and phone number, we are considering only phone name and number. We can solve this problem by considering a phone book. See the below explanation.

Explanation:- Suppose we have a phone book contain a name and phone number.

1. Ghanendra 9999999999
2. Prashant 8888888888
3. Pramod 7777777777
4. John 9898989898
5. ............................
6. ............................
n.......... So On.

Now if a person wants a number of particular people then he will enter a person name or multiple person names. Now the first person came and enter the name of the desired people.

Person 1:-

Enter name = Ghanendra
Output => Ghanendra = 9999999999

Person 2:-

Enter name = Prashant
Output => Prashant = 8888888888

Person 3:-

Enter name = John
Output => John = 9898989898

Person 4:- Now person 4 came and enter a name in Smith, as we know that Smith is not in stored in out dictionary then our program print ' Not found '. See the below example. 

Enter name = Smith
Output = Not found

Person 1:- now again if person 1 enters the name Pramod than it will print the Pramod details if exist.

Enter name = Pramod
Output => Pramod = 7777777777

I hope you got the problem statement and logic of problem, Now we can solve the problem by implementing our own function and logic or we can use the existing function. Here I am using existing function that will help me to save the time.

Tip 1:- Always try to implement the own function and logic this will help you to solve and building a logic, But you have to know that how to use the predefined function. 

1. Hackerrank Solution For Day 4: Class vs. Instance

2. Hacker Rank Solution For Day 5: Loops

3. Hackerrank Solution For Day 6: Let's Review

4. Hackerrank Solution For Day 7: Arrays

Copy the colored code and paste it into hacker rank editor. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe for our new and latest post related to programming this will help you update all about new post this Article.

Tip 2:- Before copy the program I recommended please read this full article, this will help you to build your own logic.


Submit Your Solution Here:- Click Here

Solution:-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<map>

using namespace std;
int main()
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n;
    string name;
    long num;
    cin >> n;
    cin.ignore();
    map <string,long> pbook;
    for (int i=0;i<n;i++)
    {
        cin >> name;
        cin >> num;
        pbook[name] = num;
    }
    while(cin>>name) 
    {
        if (pbook.find(name)!=pbook.end())
            cout<<name<<"="<<pbook.find(name)->second<<endl;
        else
            cout<<"Not found"<<endl;
    }
    return 0;
}


Output:-

Hacker Rank Solution For Day 8: Dictionaries and Maps

You May Also Like:-




4. Hackerrank Solution For Day 12: Inheritance

5. Hackerrank Solution For Day 13: Abstract Classes

6. Hackerrank Solution For Day 14: Scope

7. Hackerrank Solution For Day 15: Linked List

8. Hackerrank Solution For Day 16: Exceptions - String to Integer

9. Hackerrank Solution For Day 17: More Exceptions

10. Hackerrank Solution For Day 18: Queues and Stacks

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

5 comments:

  1. Replies
    1. Hello Reader I an 100% sure It's working Please make sure you choose C++ editor. For more information please leave your Email so i can send you again screenshots .
      Thanks for visiting and keep sharing

      Delete
  2. can you please explain ->second statement?

    ReplyDelete
    Replies
    1. Can you please write a statement where actually you have problem

      Delete
  3. pbook.find(name)->second

    ReplyDelete