1 Star 1 Fork 0

AlbertDarren / STL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
element_count.cpp 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
AlbertDarren 提交于 2022-04-03 00:55 . first commit
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <string>
#include <set>
using namespace std;
class cmp
{
public:
bool operator()(int val)
{
// return to_string(val).size()==2;
return to_string(val).find("7")!=-1;
}
};
int main_2()
{
srand((unsigned int)time(NULL));
vector<int> v1;
multiset<int> ms;
int random_int;
int stop=rand()%100+1;
for (int i=0; i<stop ; i++ )
{
random_int=rand()%10;
v1.push_back(random_int);
ms.insert(random_int);
}
for (int i=0; i<stop ; i++ )
{
cout << v1.at(i) << " ";
}
cout << endl;
int num=count_if(v1.begin(),v1.end(),cmp());
cout << "The number of elements including 7 is "<<num << endl;
num=count_if(v1.begin(),v1.end(),bind2nd(greater<int>(),90));//adapter
cout << "The number of elements greater than 90 is "<<num << endl;
num=count_if(v1.begin(),v1.end(),not1(bind2nd(modulus<int>(),2)));//adapter
cout << "The number of even elements is "<<num << endl;
for (multiset<int>::const_iterator it=ms.begin(); it!=ms.end() ; it++ )
{
cout << *it << " ";
}
cout << endl;
int target=4;
num=count(ms.begin(),ms.end(),target);
cout << "The number of "<<target<<" is "<<num << endl;
num=ms.count(target);
cout << "The number of "<<target<<" is "<<num << endl;
int n=distance(ms.begin(),ms.end());
cout << "The distance of two pointers is "<<n << endl;
return 0;
}
C++
1
https://gitee.com/AlbertDarren_admin/stl.git
git@gitee.com:AlbertDarren_admin/stl.git
AlbertDarren_admin
stl
STL
master

搜索帮助