lambda(待完善)

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void elimDups(vector<string>& v)
{
	sort(v.begin(), v.end());
	auto left_begin = unique(v.begin(), v.end());
	v.erase(left_begin, v.end());
}
void biggies(vector<string>& v, vector<string>::size_type sz)
{
	elimDups(v);
	stable_sort(v.begin(), v.end(),
		[](const string& s1, const string& s2) {return s1.size() < s2.size(); });
	/*auto iter = find_if(v.begin(), v.end(), [sz](const string& s) {return s.size() >= sz; });*/
	auto f = stable_partition(v.begin(), v.end(), [sz](const string& s) {return s.size() < sz; });
	int count = v.end() - f;
	cout << "The number of the strings whose size are greater than sz is " << count << endl;
	for_each(f, v.end(), [](const string& s) {cout << s << " "; });
	/*int count = v.end() - iter;
	cout << "The number of the strings whose size are greater than sz is " << count << endl;
	for_each(iter, v.end(), [](const string& s) {cout << s << " "; });
	cout << endl;*/
}
int main()
{
	vector<string>v{ "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
	biggies(v, 5);
	system("pause");
}

猜你喜欢

转载自blog.csdn.net/weixin_44009743/article/details/89285616