Search
 
SCRIPT & CODE EXAMPLE
 

CPP

search by value in map in stl/cpp

// C++ program for the above approach
#include "bits/stdc++.h"
using namespace std;
 
// Function to find the key values
// according to given mapped value K
void printKey(map<int, int>& Map,
              int K)
{
 
    // If a is true, then we have
    // not key-value mapped to K
    bool a = true;
 
    // Traverse the map
    for (auto& it : Map) {
 
        // If mapped value is K,
        // then print the key value
        if (it.second == K) {
            cout << it.first << ' ';
            a = false;
        }
    }
 
    // If there is not key mapped with K,
    // then print -1
    if (a) {
        cout << "-1";
    }
}
 
// Driver Code
int main()
{
    map<int, int> Map;
 
    // Given map
    Map[1] = 3;
    Map[2] = 3;
    Map[4] = -1;
    Map[7] = 2;
    Map[10] = 3;
 
    // Given value K
    int K = 3;
 
    // Function call
    printKey(Map, K);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: number of nodes of bst cpp 
Cpp :: how to have a queue as a parameter in c++ 
Cpp :: c++ math 
Cpp :: passing custom function in sort cpp 
Cpp :: c++ recursion 
Cpp :: abstraction in cpp 
Cpp :: How to split a string by Specific Delimiter in C/C++ 
Cpp :: find pair with given sum in the array 
Cpp :: c++ check if key exists in map 
Cpp :: c++ fonksion pointer 
Cpp :: Translation codeforces in c++ 
Cpp :: pointers and arrays in c++ 
Cpp :: c++ open webpage 
Cpp :: c++ delay 
Cpp :: c++ regex count number of matches 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: how to use for c++ 
Cpp :: ascii allowed in c++ 
Cpp :: c ++ program to insert into hashmap 
Cpp :: how to print an array in cpp in single line 
Cpp :: C++ Nested if 
Cpp :: what algorithm does bitcoin use 
Cpp :: c++ create function pointer 
Cpp :: abs c++ 
Cpp :: how to modify 2d array in function c++ 
Cpp :: Write a C++ program using constructor 
Cpp :: logisch oder 
Cpp :: largest subarray with zero sum 
Cpp :: surf interpolation matlab 
Cpp :: c++ get microseconds since epoch 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =