#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
using namespace std;
#include<algorithm>
int main()
{
vector<int> v;
srand(static_cast<unsigned int>(time(nullptr)));
for (int i = 0;i < 100;i++)
{
int randValue = rand() % 100;
v.push_back(randValue);
}
{
int number = 50;
bool found = false;
vector<int>::iterator it;
vector<int>::iterator itFind = find(v.begin(),v.end(),number);
if (itFind == v.end()) {
cout << "못 찾음" << endl;
}
else {
cout << "찾음" << endl;
found = true;
}
int a = 3;
}
{
bool found = false;
vector<int>::iterator it;
struct CanDivideBy11 {
bool operator()(int n) {
return (n % 11) == 0;
}
};
vector<int>::iterator itFind=find_if(v.begin(), v.end(), CanDivideBy11());
if (itFind == v.end()) {
cout << "못 찾음" << endl;
}
else {
cout << "찾음" << endl;
found = true;
}
int a = 3;
}
{
int count = 0;
struct IsOdd {
bool operator()(int n) {
return (n % 2) != 0;
}
};
count = count_if(v.begin(), v.end(), IsOdd());
cout << count << endl;
bool b1= all_of(v.begin(), v.end(), IsOdd());
bool b2 = any_of(v.begin(), v.end(), IsOdd());
bool b3 = none_of(v.begin(), v.end(), IsOdd());
cout << b1 << " " << b2 << " " << b3 << endl;
int a = 3;
}
{
struct MultiplyBy3 {
void operator()(int n) {
n= n * 3;
}
};
for_each(v.begin(), v.end(), MultiplyBy3());
int a = 3;
}
{
for (vector<int>::iterator it = v.begin();it != v.end();) {
if ((*it % 2) != 0) {
it=v.erase(it);
}
else {
++it;
}
}
v.clear();
v.push_back(4);
v.push_back(3);
v.push_back(5);
v.push_back(8);
v.push_back(2);
struct IsOdd {
bool operator()(int n) {
return (n % 2) != 0;
}
};
vector<int>::iterator it = remove_if(v.begin(), v.end(), IsOdd());
v.erase(it, v.end());
int a = 3;
}
return 0;
}