Sunday, November 13, 2016

Dictionaries and maps : C++

Problem
Code :
 #include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
    int n;
    string name;
    long num;
    //cin.ignore();
    cin>>n;
    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;
}

No comments:

Post a Comment

Search This Blog