it = adjacent_find (it, myvector.end(), myfunction);
if (it!=myvector.end())
cout << "the second consecutive repeated elements are: "<< *it << endl;
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[1000]={1,2,3,3,3,4,4,5};
int y=count(a,a8,3); //(数组名,查询的数组长度,查询个数的数字)
cout<<"number of times "<<y<<endl;
return 0;
}
输出结果:
number of times 3
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int ival , searchValue;
vector<int> ivec;
cout<<"Enter some integers(CtrlZ to end):"<<endl;
while(cin >> ival)
ivec.push_back(ival);
cin.clear();// 使输入流重新有效
cout<<"Enter an integer you want to search:"<<endl;
cin>>searchValue;
cout<<count(ivec.begin() , ivec.end() , searchValue)
<<" elements in thevector have value "
<<searchValue<<endl;
return 0;
}
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
bool greater10(int value)
{
return value >10;
}
int main()
{
vector<int> v1;
vector<int>::iterator Iter;
v1.push_back(10);
v1.push_back(20);
v1.push_back(10);
v1.push_back(40);
v1.push_back(10);
cout << "v1 : ";
for (Iter = v1.begin(); Iter != v1.end(); Iter)
cout << *Iter << " ";
cout << endl;
vector<int>::size_typeresult1 = count_if(v1.begin(), v1.end(), greater10); //count_if算法返回使谓词函数返回条件成立的元素个数
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-19.html
敌不动
也许是之前中国放出去的