#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> v = {1,3,5,7,9};
auto isEven = [](int i){return i % 2 != 0;}
bool isallOdd = std::allof(v.begin(), v.end(),isEven);
if(isallOdd)
cout << "all is odd" << endl;
bool isNoneEven = std::noneof(v.begin(), v.end(),isEven);
if(isNoneEven)
cout << "none is even" << endl;
vector<int> v1 = {1,3,5,7,8,9};
bool anyof = std::any_of(v.begin(), v.end(),isEven);
if(anyof)
cout << "at least one is even" << endl;
}
/*
输出结果:
*/
#include <numeric>
#include <array>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> v(4);
//循环遍历赋值来初始化数组
/*
for(int i=1;i<=4;i++)
{
v.push_back(i);
}
*/
//直接通过iota初始化数组,更简洁
std::iota(v.begin(), v.end(),1);
for(auto n : v)
{
cout << n << ‘ ‘;
}
cout << endl;
std::array<int,4>array;
std::iota(array.begin(), array.end(), 1);
for(auto n: array)
{
cout << n << ‘ ‘;
}
std::cout << endl;
}
/*
输出结果:
1 2 3 4
1 2 3 4
*/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
//your code goes here
vector<int> v = {1,2,5,7,9,4};
auto result = minmax_element(v.begin(), v.end());
cout<<*result.first<<" "<<*result.second<<endl;
return 0;
}
原文:https://www.cnblogs.com/fewolflion/p/12968641.html