代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。