-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpred1.cpp
46 lines (39 loc) · 940 Bytes
/
pred1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
struct Greater_than {
int val;
Greater_than(int v) : val{v} {}
bool operator()(const pair<string, int> &r) { return r.second > val;}
};
void f(map<string, int> &m, int v)
{
auto p = m.begin();
while ((p = find_if(p, m.end(), Greater_than{v})) != m.end()) {
cout << p->first << " " << p->second<< endl;
++p;
}
}
void f_lambda(map<string, int> &m, int v)
{
auto p = m.begin();
while ((p = find_if(p, m.end(), [&v](const pair<string, int> &r) { return r.second > v;})) != m.end()) {
cout << p->first << " " << p->second<< endl;
++p;
}
}
int main()
{
map<string, int> empl;
empl["Prasanth"] = 36;
empl["Durga"] = 5;
empl["Lakshmi"] = 1;
empl["Swapna"] = 33;
f(empl, 1);
f_lambda(empl, 5);
return 0;
}