Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- void Print(const vector <int>& v, const string& title)
- {
- cout << title << ": ";
- for (auto i : v)
- {
- cout << i << ' ';
- }
- }
- bool Gt2(int x)
- {
- if (x > 2)
- {
- return true;
- }
- return false;
- }
- bool Lt2(int x)
- {
- if (x < 2)
- {
- return true;
- }
- return false;
- }
- int main()
- {
- vector<int> v = { 1,3,5,2,4 };
- cout << count(begin(v), end(v), 2);
- cout << count_if(begin(v), end(v), Gt2);
- cout << endl;
- cout << count_if(begin(v), end(v), Lt2);
- int thr = 0;
- cin >> thr;
- cout << count_if(begin(v), end(v), [thr](int x)
- {
- if (x > thr)
- {
- return true;
- }
- return false;
- });
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement