Saturday, 1 April 2017

Hacker Rank Solution Program In C++ For " Day 8: Dictionaries and Maps "

Problem :- Day 8: Dictionaries and Maps

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

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 Program In C++ For " Day 8: Dictionaries and Maps "

5 comments:
Write 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

Recommended Posts × +